alphagov/whitehall — pull request #1563 by tekin (2014-06-16 10:46:28+00:00)
Title: Remove hardcoded ENV and domain knowledge

This deals with some long-standing technical debt with whitehall's use of hardcoded domains in the codebase. Up to now, the app has had too much knowledge of the different domains and environments the app is hosted on and the way these map to backend and public-facing URLs. These changes remove that knowledge. Instead, we rely on Plek (which uses the GOVUK_APP_DOMAIN environment variable) to tell us both the public and backend domains and treat every environment the same.

As well as greatly simplifying the codebase (and allowing me to perform an extraction I need as part of [another story](https://www.agileplannerapp.com/boards/173808/cards/3358)), this will make the [provisioning of team-specific test environments](https://www.pivotaltracker.com/story/show/71470506) a lot easier (i.e. possible).

## Static assets in development mode

This also changes the default behaviour of static asset serving in development mode. Up to now, static assets have been served from preview when in development mode by default. This is so developers do not need to run a separate copy of static locally when developing whitehall. This was different to how all other apps work and has been reversed: now by default, whitehall looks for static wherever Plek tells it to look. If a developer does not want to run static locally, they can override this by setting the `STATIC_DEV` environment variable, e.g.

```
STATIC_DEV=https://static.preview.alphagov.co.uk bundle exec rails server
```

The `./startup.sh` script has been updated to set this env var. Behaviour when using `bowler` or `forman` is maintained, i.e. a static server is started locally.

## Exceptions

There are a couple of places in the codebase where we still have hardcoded knowledge of the envs and domains: The main one is `BadLinkReporter`, which needs to generate production links but is run on a backend preview box at present. The other is the setting of `GOVUK_APP_DOMAIN` and `GOVUK_ASSET_ROOT` in test mode so that tests can be run without having to explicitly set them first.