From a6d365450c4f288afd9a84960bd8f281b120d8f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=83=9D=E3=83=BC=E3=83=AB=20=E3=82=A6=E3=82=A7=E3=83=83?= =?UTF-8?q?=E3=83=96?= Date: Tue, 8 Jan 2019 12:46:29 -0600 Subject: [PATCH] Removed "heroku-ssl-redirect" package --- package.json | 1 - server.js | 27 ++++++++++++--------------- 2 files changed, 12 insertions(+), 16 deletions(-) diff --git a/package.json b/package.json index 6ddfca7..bf6a0b4 100755 --- a/package.json +++ b/package.json @@ -29,7 +29,6 @@ "fs-exists-sync": "^0.1.0", "got": "^9.5.0", "graceful-fs": "^4.1.15", - "heroku-ssl-redirect": "0.0.4", "make-promises-safe": "^4.0.0", "markdown-it": "^8.4.2", "markdown-it-anchor": "^5.0.2", diff --git a/server.js b/server.js index b6773a4..d518492 100755 --- a/server.js +++ b/server.js @@ -7,7 +7,6 @@ const color = require("colorette"); const cors = require("cors"); const local = require("app-root-path").require; -// const ssl = require("heroku-ssl-redirect"); const fastify = require("fastify")({ logger: { @@ -26,7 +25,6 @@ const messageSlack = local("app/helpers/slack").default; // P R O G R A M fastify - // .use(ssl()) .use(cors()) .register(require("fastify-compress")) .register(require("@inc/fastify-ws")) @@ -39,20 +37,19 @@ fastify }) .register(require("choo-ssr/fastify"), { app: require("./app") + }) + .addHook("preHandler", (request, reply, next) => { + if (process.env.NODE_ENV !== "development") { + if (request.headers["x-forwarded-proto"] !== "https") + reply.redirect(302, `https://${request.raw.hostname}${request.raw.originalUrl}`); + + else + next(); + } + + next(); }); -fastify.addHook("preHandler", (request, reply, next) => { - if (process.env.NODE_ENV !== "development") { - if (request.headers["x-forwarded-proto"] !== "https") - reply.redirect(302, "https://" + request.raw.hostname + request.raw.originalUrl); - - else - next(); - } - - next(); -}); - fastify.ready(err => { if (err) throw err; @@ -73,7 +70,7 @@ fastify.ready(err => { const start = async() => { try { await fastify.listen(process.env.PORT || 8080, process.env.IP || "0.0.0.0"); - } catch (err) { + } catch(err) { fastify.log.error(err); process.exit(1); }