From 1321839e1f5fb5a4ebdbe614fba8b5c2d2d489f3 Mon Sep 17 00:00:00 2001 From: Michael Eden Date: Fri, 13 Oct 2017 10:53:41 -0400 Subject: [PATCH] Correctly set secure flag by trusting CF proxy. --- deployment.yaml | 1 + server/app.ts | 4 ++++ server/config.ts | 4 +++- server/graphql.ts | 2 +- 4 files changed, 9 insertions(+), 2 deletions(-) diff --git a/deployment.yaml b/deployment.yaml index 66a0d45..b6a4062 100644 --- a/deployment.yaml +++ b/deployment.yaml @@ -7,6 +7,7 @@ secrets: - DEFAULT_ADMIN_PASS env: + PRODUCTION: true REGISTRATION_GRAPHQL: "https://registration.dev.hack.gt/graphql" wants: diff --git a/server/app.ts b/server/app.ts index 2fa5571..4a06e64 100644 --- a/server/app.ts +++ b/server/app.ts @@ -58,6 +58,10 @@ const VERSION_HASH = require("git-rev-sync").short(); export let app = express(); +if (config.server.production) { + app.enable("trust proxy"); +} + app.use(compression()); let cookieParserInstance = cookieParser(undefined, { "path": "/", diff --git a/server/config.ts b/server/config.ts index a0180ea..9298079 100644 --- a/server/config.ts +++ b/server/config.ts @@ -2,6 +2,7 @@ export interface IConfig { server: { port: number; mongo: string; + production: boolean; }, inputs: { registration: string; @@ -20,7 +21,8 @@ export interface IConfig { export const config: IConfig = { server: { port: envOrDefaultMap("PORT", 3000, parseInt), - mongo: envOrDefault("MONGO_URL", "mongodb://localhost/checkin") + mongo: envOrDefault("MONGO_URL", "mongodb://localhost/checkin"), + production: envOrDefault("PRODUCTION", "false").toLowerCase() === "true", }, inputs: { registration: envOrDefault("REGISTRATION_GRAPHQL", "https://registration.dev.hack.gt/graphql") diff --git a/server/graphql.ts b/server/graphql.ts index 2e4da78..0571dbc 100644 --- a/server/graphql.ts +++ b/server/graphql.ts @@ -286,7 +286,7 @@ export function setupRoutes(app: express.Express, registration: Registration) { (request, response, next) => { graphiqlExpress({ endpointURL: "/graphql", - subscriptionsEndpoint: createLink(request, "graphql", "wss") + subscriptionsEndpoint: createLink(request, "graphql", "ws") })(request, response, next); } );