mirror of
https://github.com/hydra-synth/hydra.git
synced 2025-12-15 03:10:01 +01:00
backend in separate module
This commit is contained in:
29
backend/configure-ssl.js
Normal file
29
backend/configure-ssl.js
Normal file
@@ -0,0 +1,29 @@
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
|
||||
// if on glitch, force https
|
||||
module.exports = (app) => {
|
||||
var server
|
||||
if(process.env.GLITCH) {
|
||||
var http = require('http')
|
||||
server = http.createServer(app)
|
||||
|
||||
function checkHttps(req, res, next){
|
||||
if(req.get('X-Forwarded-Proto').indexOf("https")!=-1){
|
||||
// console.log("https, yo")
|
||||
return next()
|
||||
} else {
|
||||
res.redirect('https://' + req.hostname + req.url);
|
||||
}
|
||||
}
|
||||
|
||||
app.all('*', checkHttps)
|
||||
} else {
|
||||
var https = require('https')
|
||||
var privateKey = fs.readFileSync(path.join(__dirname, '/certs/key.pem'), 'utf8')
|
||||
var certificate = fs.readFileSync(path.join(__dirname, '/certs/certificate.pem'), 'utf8')
|
||||
var credentials = {key: privateKey, cert: certificate}
|
||||
server = https.createServer(credentials, app)
|
||||
}
|
||||
return server
|
||||
}
|
||||
Reference in New Issue
Block a user