diff --git a/api/config/default.js b/api/config/default.js index 89b923115..01ec52ea7 100644 --- a/api/config/default.js +++ b/api/config/default.js @@ -100,4 +100,8 @@ module.exports = { * Token expiration delay */ nbMaxDayTokenLife: 30, + /** + * Force HTTP to HTTPS + */ + forceSSL: false, } diff --git a/api/config/production.js b/api/config/production.js index 9b9570746..3a61f9271 100644 --- a/api/config/production.js +++ b/api/config/production.js @@ -7,4 +7,5 @@ module.exports = { sendingBlue: { usersListId: 8, }, + forceSSL: true, } diff --git a/api/config/sandbox.js b/api/config/sandbox.js index 832e71a0e..f19ba362b 100644 --- a/api/config/sandbox.js +++ b/api/config/sandbox.js @@ -8,4 +8,5 @@ module.exports = { sendingBlue: { usersListId: 9, }, + forceSSL: true, } diff --git a/api/config/staging.js b/api/config/staging.js index 959d8ad15..b06356f4b 100644 --- a/api/config/staging.js +++ b/api/config/staging.js @@ -8,4 +8,5 @@ module.exports = { sendingBlue: { usersListId: 7, }, + forceSSL: true, } diff --git a/api/src/routes/RouteIndex.js b/api/src/routes/RouteIndex.js index 4c4d72daf..bf3031124 100644 --- a/api/src/routes/RouteIndex.js +++ b/api/src/routes/RouteIndex.js @@ -1,6 +1,7 @@ import { createReadStream, existsSync } from 'fs' import mime from 'mime' import Route from './Route' +import config from 'config' @Route.Route({ routeBase: '', @@ -15,6 +16,16 @@ export default class RouteIndex extends Route { path: '*', }) async readFile(ctx) { + console.log('config', config) + if (!config.forceURL && ctx.request?.header?.referer && ctx.request.header.referer.startsWith('http:')) { + ctx.res + .writeHead(301, { + Location: ctx.request.header.referer.replace('http', 'https'), + }) + .end() + } + + console.log(ctx) let file = `${__dirname}/../front${decodeURIComponent(ctx.request.url)}` const fileSplited = file.split('?') file = fileSplited.length > 1 ? fileSplited.slice(0, -1).join('?') : file