Move basic auth after SSL redirection

This commit is contained in:
Boyan Tabakov 2017-05-17 14:39:03 +03:00
parent 49b52b0506
commit e56583011e

View file

@ -42,13 +42,6 @@ const app = express();
// See: https://www.npmjs.com/package/helmet
app.use(helmet());
// Use basic authentication when not in dev mode.
if (!dev) {
const USERNAME = process.env.BASIC_AUTH_USERNAME;
const PASSWORD = process.env.BASIC_AUTH_PASSWORD;
app.use(auth.basicAuth(USERNAME, PASSWORD));
}
// Redirect HTTP to HTTPS if ENFORCE_SSL is `true`.
// This also works behind reverse proxies (load balancers) as they are for example used by Heroku.
// In such cases, however, the TRUST_PROXY parameter has to be set (see below)
@ -73,6 +66,13 @@ if (TRUST_PROXY === 'true') {
app.set('trust proxy', TRUST_PROXY);
}
// Use basic authentication when not in dev mode.
if (!dev) {
const USERNAME = process.env.BASIC_AUTH_USERNAME;
const PASSWORD = process.env.BASIC_AUTH_PASSWORD;
app.use(auth.basicAuth(USERNAME, PASSWORD));
}
app.use(compression());
app.use('/static', express.static(path.join(buildPath, 'static')));
app.use(cookieParser());