Explorar el Código

Add TLS support

production
Jack Foltz hace 5 años
padre
commit
dd0f4647fc
Firmado por: foltik <jack@foltz.io> ID de clave GPG: D1F0331758D1F29A
Se han modificado 5 ficheros con 23 adiciones y 7 borrados
  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 Ver fichero

@@ -1,7 +1,8 @@
{
"Server": {
"port": 4433,
"hostname": "https://shimapan.rocks"
"hostname": "https://shimapan.rocks",
"tls": true
},
"Database": {
"host": "mongodb://localhost:27017/shimapan"


+ 2
- 1
config/dev.json Ver fichero

@@ -1,7 +1,8 @@
{
"Server": {
"port": 8080,
"hostname": "http://localhost:8080"
"hostname": "http://localhost:8080",
"tls": false
},
"Database": {
"host": "mongodb://localhost:27017/shimapan-dev"


+ 2
- 1
config/test.json Ver fichero

@@ -1,7 +1,8 @@
{
"Server": {
"port": 8080,
"hostname": "http://localhost:8080"
"hostname": "http://localhost:8080",
"tls": false
},
"Database": {
"host": "mongodb://localhost:27017/shimapan-test"


+ 2
- 1
package.json Ver fichero

@@ -55,7 +55,8 @@
"test": "npx mocha",
"build": "npx gulp",
"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": {
"type": "git",


+ 15
- 3
server.js Ver fichero

@@ -1,3 +1,5 @@
const https = require('https');
const fs = require('fs');
const express = require('express');
const bodyParser = require('body-parser');
const methodOverride = require('method-override');
@@ -70,9 +72,19 @@ app.use((err, req, res, next) => {

// Start app
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
module.exports.app = app;


Cargando…
Cancelar
Guardar