mirror of
https://github.com/hydra-synth/hydra.git
synced 2025-12-14 18:59:59 +01:00
falling back to HTTP if no certificate is found
This commit is contained in:
@@ -4,8 +4,9 @@ const path = require('path')
|
|||||||
// if on glitch, force https
|
// if on glitch, force https
|
||||||
module.exports = (app) => {
|
module.exports = (app) => {
|
||||||
var server
|
var server
|
||||||
|
|
||||||
if(process.env.GLITCH) {
|
if(process.env.GLITCH) {
|
||||||
var http = require('http')
|
var http = require('http')
|
||||||
server = http.createServer(app)
|
server = http.createServer(app)
|
||||||
|
|
||||||
function checkHttps(req, res, next){
|
function checkHttps(req, res, next){
|
||||||
@@ -19,11 +20,22 @@ module.exports = (app) => {
|
|||||||
|
|
||||||
app.all('*', checkHttps)
|
app.all('*', checkHttps)
|
||||||
} else {
|
} else {
|
||||||
var https = require('https')
|
try {
|
||||||
var privateKey = fs.readFileSync(path.join(__dirname, '/certs/key.pem'), 'utf8')
|
var https = require('https')
|
||||||
var certificate = fs.readFileSync(path.join(__dirname, '/certs/certificate.pem'), 'utf8')
|
var privateKey = fs.readFileSync(path.join(__dirname, '/certs/key.pem'), 'utf8')
|
||||||
var credentials = {key: privateKey, cert: certificate}
|
var certificate = fs.readFileSync(path.join(__dirname, '/certs/certificate.pem'), 'utf8')
|
||||||
server = https.createServer(credentials, app)
|
var credentials = {key: privateKey, cert: certificate}
|
||||||
|
server = https.createServer(credentials, app)
|
||||||
|
} catch (err) {
|
||||||
|
if (err.code === 'ENOENT') {
|
||||||
|
console.log("no TLS certificate at", err.path)
|
||||||
|
var http = require('http')
|
||||||
|
server = http.createServer(app)
|
||||||
|
} else {
|
||||||
|
throw err
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return server
|
return server
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user