var fs = require('fs')
var http = require('http')
var https = require('https')
var app = require('express')()
var privateKey = fs.readFileSync('./cert/server.key', 'utf8')
var certificate = fs.readFileSync('./cert/server.crt', 'utf8')
var credentials = { key: privateKey, cert: certificate }
var httpServer = http.createServer(app)
var httpsServer = https.createServer(credentials, app)
var PORT = 80
var SSLPORT = 443
httpServer.listen(PORT, function () {
console.log('HTTP Server is running on: http://localhost:%s', PORT)
})
httpsServer.listen(SSLPORT, function () {
console.log('HTTPS Server is running on: https://localhost:%s', SSLPORT)
})
// Welcome
app.get('/', function (req, res) {
if (req.protocol === 'https') {
res.status(200).send('Welcome to Safety Land!')
} else {
res.status(200).send('Welcome!')
}
})