@@ -1,7 +1,8 @@ | |||||
{ | { | ||||
"Server": { | "Server": { | ||||
"port": 4433, | "port": 4433, | ||||
"hostname": "https://shimapan.rocks" | |||||
"hostname": "https://shimapan.rocks", | |||||
"tls": true | |||||
}, | }, | ||||
"Database": { | "Database": { | ||||
"host": "mongodb://localhost:27017/shimapan" | "host": "mongodb://localhost:27017/shimapan" | ||||
@@ -1,7 +1,8 @@ | |||||
{ | { | ||||
"Server": { | "Server": { | ||||
"port": 8080, | "port": 8080, | ||||
"hostname": "http://localhost:8080" | |||||
"hostname": "http://localhost:8080", | |||||
"tls": false | |||||
}, | }, | ||||
"Database": { | "Database": { | ||||
"host": "mongodb://localhost:27017/shimapan-dev" | "host": "mongodb://localhost:27017/shimapan-dev" | ||||
@@ -1,7 +1,8 @@ | |||||
{ | { | ||||
"Server": { | "Server": { | ||||
"port": 8080, | "port": 8080, | ||||
"hostname": "http://localhost:8080" | |||||
"hostname": "http://localhost:8080", | |||||
"tls": false | |||||
}, | }, | ||||
"Database": { | "Database": { | ||||
"host": "mongodb://localhost:27017/shimapan-test" | "host": "mongodb://localhost:27017/shimapan-test" | ||||
@@ -55,7 +55,8 @@ | |||||
"test": "npx mocha", | "test": "npx mocha", | ||||
"build": "npx gulp", | "build": "npx gulp", | ||||
"start": "npx gulp start", | "start": "npx gulp start", | ||||
"watch": "npx gulp watch" | |||||
"watch": "npx gulp watch", | |||||
"genkey": "openssl req -newkey rsa:2048 -nodes -keyout privkey.pem -x509 -days 3650 -out cert.pem" | |||||
}, | }, | ||||
"repository": { | "repository": { | ||||
"type": "git", | "type": "git", | ||||
@@ -1,3 +1,5 @@ | |||||
const https = require('https'); | |||||
const fs = require('fs'); | |||||
const express = require('express'); | const express = require('express'); | ||||
const bodyParser = require('body-parser'); | const bodyParser = require('body-parser'); | ||||
const methodOverride = require('method-override'); | const methodOverride = require('method-override'); | ||||
@@ -70,9 +72,19 @@ app.use((err, req, res, next) => { | |||||
// Start app | // Start app | ||||
const port = config.get('Server.port'); | const port = config.get('Server.port'); | ||||
const server = app.listen(port, () => { | |||||
console.log('Listening on port ' + port + '...\n'); | |||||
}); | |||||
let server; | |||||
if (config.get('Server.tls')) { | |||||
const options = { | |||||
cert: fs.readFileSync('./cert.pem'), | |||||
key: fs.readFileSync('./privkey.pem'), | |||||
}; | |||||
server = https.createServer(options, app).listen(port, () => | |||||
console.log(`Listening on port ${port}...`)); | |||||
} else { | |||||
server = app.listen(port, () => | |||||
console.log(`Listening on port ${port}...`)); | |||||
} | |||||
// Expose app | // Expose app | ||||
module.exports.app = app; | module.exports.app = app; | ||||