Skip to content

Commit

Permalink
fix(frontend): fix middleware chain on prod (#2406)
Browse files Browse the repository at this point in the history
* fix(frontend): fix middleware chain on prod

* add await

* fix env version
  • Loading branch information
lionelB authored Feb 25, 2020
1 parent eeea568 commit e6dc054
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions packages/code-du-travail-frontend/server/server.js
Original file line number Diff line number Diff line change
@@ -16,7 +16,7 @@ const PORT = parseInt(process.env.FRONTEND_PORT, 10) || 3000;
const FRONTEND_HOST = process.env.FRONTEND_HOST || `http://localhost:${PORT}`;
const PROD_HOSTNAME = process.env.PROD_HOSTNAME || "code.travail.gouv.fr";
const SENTRY_PUBLIC_DSN = process.env.SENTRY_PUBLIC_DSN;
const PACKAGE_VERSION = process.env.PACKAGE_VERSION || "";
const PACKAGE_VERSION = process.env.VERSION || "";

function getSentryCspUrl() {
// NOTE(douglasduteil): is pre production if we can find the version in the url
@@ -103,14 +103,15 @@ nextApp.prepare().then(() => {
});
}
if (IS_PRODUCTION_DEPLOYMENT) {
server.use(async function(ctx) {
server.use(async function(ctx, next) {
const isProdUrl = ctx.host === PROD_HOSTNAME;
const isHealthCheckUrl = ctx.path === "/health";
if (!isProdUrl && !isHealthCheckUrl) {
ctx.status = 301;
ctx.redirect(`https://${PROD_HOSTNAME}${ctx.originalUrl}`);
return;
}
await next();
});
} else {
server.use(async function(ctx, next) {

0 comments on commit e6dc054

Please sign in to comment.