Преглед на файлове

Add TLS support

production
Jack Foltz преди 5 години
родител
ревизия
dd0f4647fc
Signed by: foltik <jack@foltz.io> GPG Key ID: D1F0331758D1F29A
променени са 5 файла, в които са добавени 23 реда и са изтрити 7 реда
  1. +2
    -1
      config/default.json
  2. +2
    -1
      config/dev.json
  3. +2
    -1
      config/test.json
  4. +2
    -1
      package.json
  5. +15
    -3
      server.js

+ 2
- 1
config/default.json Целия файл

@@ -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"


+ 2
- 1
config/dev.json Целия файл

@@ -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"


+ 2
- 1
config/test.json Целия файл

@@ -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"


+ 2
- 1
package.json Целия файл

@@ -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",


+ 15
- 3
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…
Отказ
Запис