aboutsummaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorNoah Loomans <noahloomans@gmail.com>2017-05-26 17:36:50 +0200
committerNoah Loomans <noahloomans@gmail.com>2017-05-26 18:11:19 +0200
commitd37fe2a83897569a18dfb45809143c152c497e95 (patch)
tree2d254cad57b640e48556b0bebc2cd8c78750442b /bin
parentfd8362125f5bd78c8328afae79549cb2a771f32a (diff)
Remove HTTPS as this is now handled by nginx
Diffstat (limited to 'bin')
-rwxr-xr-xbin/www75
1 files changed, 9 insertions, 66 deletions
diff --git a/bin/www b/bin/www
index 4c375d3..545db41 100755
--- a/bin/www
+++ b/bin/www
@@ -1,52 +1,14 @@
#!/usr/bin/env node
-const fs = require('fs')
const app = require('../app')
const http = require('http')
-const https = require('spdy')
-const fileLocations = {
- cert: '/etc/letsencrypt/live/rooster.hetmml.nl/fullchain.pem',
- privkey: '/etc/letsencrypt/live/rooster.hetmml.nl/privkey.pem'
-}
-
-function setupHTTPS () {
- const certificate = fs.readFileSync(fileLocations.cert, 'utf8')
- const privateKey = fs.readFileSync(fileLocations.privkey, 'utf8')
- const credentials = { key: privateKey, cert: certificate }
-
- const httpsPort = normalizePort(process.env.PORT_HTTPS || '3001')
- const httpsServer = https.createServer(credentials, app)
+const port = normalizePort(process.env.PORT || '3000')
+const server = http.createServer(app)
- httpsServer.listen(httpsPort)
- httpsServer.on('error', error => onError(error, httpsPort))
- httpsServer.on('listening', _ => onListening(httpsServer))
-
- app.set('port', httpsPort)
-}
-
-function redirectToHTTPS (req, res) {
- res.writeHead(301, { 'Location': 'https://' + req.headers['host'] + req.url })
- res.end()
-}
-
-function setupHTTPSRedirect () {
- const httpPort = normalizePort(process.env.PORT || '3000')
- const httpServer = http.createServer(redirectToHTTPS)
-
- httpServer.listen(httpPort)
- httpServer.on('error', error => onError(error, httpPort))
- httpServer.on('listening', _ => onListening(httpServer))
-}
-
-function setupHTTP () {
- const httpPort = normalizePort(process.env.PORT || '3000')
- const httpServer = http.createServer(app)
-
- httpServer.listen(httpPort)
- httpServer.on('error', error => onError(error, httpPort))
- httpServer.on('listening', _ => onListening(httpServer))
-}
+server.listen(port)
+server.on('error', error => onError(error, port))
+server.on('listening', _ => onListening(server))
function normalizePort (val) {
const port = parseInt(val, 10)
@@ -90,28 +52,9 @@ function onError (error, port) {
function onListening (server) {
const addr = server.address()
- const bind = typeof addr === 'string'
- ? 'pipe ' + addr
- : 'port ' + addr.port
- console.log('Listening on ' + bind)
-}
-
-let useHTTPS = true
-try {
- fs.accessSync(fileLocations.privkey)
-} catch (e) {
- useHTTPS = false
-}
-
-if (useHTTPS) {
- try {
- setupHTTPS()
- setupHTTPSRedirect()
- } catch (e) {
- console.warn('NOT USING HTTPS! Error occured while setting up HTTPS')
- setupHTTP()
+ if (typeof addr === 'string') {
+ console.log(`Listening on pipe ${addr}`)
+ } else {
+ console.log(`Listening on http://localhost:${addr.port}/`)
}
-} else {
- console.warn(`NOT USING HTTPS! Could not read ${fileLocations.privkey}`)
- setupHTTP()
}