mirror of
https://github.com/Foltik/Shimapan
synced 2024-11-30 22:41:47 -05:00
Add TLS support
This commit is contained in:
parent
70ba0706a3
commit
dd0f4647fc
@ -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",
|
||||||
|
18
server.js
18
server.js
@ -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;
|
||||||
|
Loading…
Reference in New Issue
Block a user