Skip to content

Commit

Permalink
update ssl
Browse files Browse the repository at this point in the history
  • Loading branch information
fxmontigny committed Aug 1, 2023
1 parent e47d2f0 commit 0b0cd61
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 0 deletions.
4 changes: 4 additions & 0 deletions api/config/default.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,8 @@ module.exports = {
* Token expiration delay
*/
nbMaxDayTokenLife: 30,
/**
* Force HTTP to HTTPS
*/
forceSSL: false,
}
1 change: 1 addition & 0 deletions api/config/production.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ module.exports = {
sendingBlue: {
usersListId: 8,
},
forceSSL: true,
}
1 change: 1 addition & 0 deletions api/config/sandbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ module.exports = {
sendingBlue: {
usersListId: 9,
},
forceSSL: true,
}
1 change: 1 addition & 0 deletions api/config/staging.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ module.exports = {
sendingBlue: {
usersListId: 7,
},
forceSSL: true,
}
11 changes: 11 additions & 0 deletions api/src/routes/RouteIndex.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { createReadStream, existsSync } from 'fs'
import mime from 'mime'
import Route from './Route'
import config from 'config'

@Route.Route({
routeBase: '',
Expand All @@ -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
Expand Down

0 comments on commit 0b0cd61

Please sign in to comment.