Added HTTPS to express
This commit is contained in:
@@ -1,10 +1,11 @@
|
||||
DATABASE =FreePlanet
|
||||
TEST_ATTIVO=1
|
||||
PORT=3000
|
||||
URLBASE_APP1=http://freeplanet.app
|
||||
URLBASE_APP1=https://freeplanet.app
|
||||
PORT_APP1=80
|
||||
DOMAIN=mongodb://localhost:27017/
|
||||
SIGNCODE=abc123
|
||||
EMAIL_FROM=perseo774.un@gmail.com
|
||||
EMAIL_PW=passpao1UNOK
|
||||
SEND_EMAIL="0"
|
||||
DEBUG=true
|
||||
|
||||
@@ -3,13 +3,14 @@ module.exports = {
|
||||
{
|
||||
name: "FreePlanetServerSide",
|
||||
script: "./server/server.js",
|
||||
ignore_watch : ["node_modules"],
|
||||
watch: true,
|
||||
env: {
|
||||
"PORT": 3000,
|
||||
"NODE_ENV": "development"
|
||||
},
|
||||
env_production: {
|
||||
"PORT": 8080,
|
||||
"PORT": 3000,
|
||||
"NODE_ENV": "production",
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// still in app.js
|
||||
const node_env = process.env.NODE_ENV || 'development';
|
||||
const node_env = process.env.NODE_ENV || 'production';
|
||||
var file = `.env.${node_env}`;
|
||||
|
||||
// GLOBALI (Uguali per TUTTI)
|
||||
|
||||
@@ -8,6 +8,8 @@ const _ = require('lodash');
|
||||
// Resolving error Unknown modifier: $pushAll
|
||||
mongoose.plugin(schema => { schema.options.usePushEach = true });
|
||||
|
||||
mongoose.set('debug', process.env.DEBUG);
|
||||
|
||||
var UserSchema = new mongoose.Schema({
|
||||
email: {
|
||||
type: String,
|
||||
|
||||
@@ -2,8 +2,25 @@ require('./config/config');
|
||||
|
||||
const _ = require('lodash');
|
||||
const cors = require('cors');
|
||||
var express = require('express'),
|
||||
i18n = require("i18n");
|
||||
|
||||
var fs = require('fs');
|
||||
var http = require('http');
|
||||
var https = require('https');
|
||||
|
||||
const port = process.env.PORT;
|
||||
|
||||
if (process.env.PROD) {
|
||||
var privateKey = fs.readFileSync('sslcert/server.key', 'utf8');
|
||||
var certificate = fs.readFileSync('sslcert/server.crt', 'utf8');
|
||||
var credentials = {key: privateKey, cert: certificate};
|
||||
porthttp = port + 1
|
||||
}else{
|
||||
porthttp = port
|
||||
}
|
||||
|
||||
var express = require('express');
|
||||
|
||||
var i18n = require("i18n");
|
||||
|
||||
|
||||
console.log("DB: " + process.env.DATABASE);
|
||||
@@ -37,7 +54,6 @@ app.use(cors({
|
||||
exposedHeaders: ['x-auth'],
|
||||
}));
|
||||
|
||||
const port = process.env.PORT;
|
||||
|
||||
app.use(bodyParser.json());
|
||||
|
||||
@@ -259,9 +275,18 @@ app.delete('/users/me/token', authenticate, (req, res) => {
|
||||
});
|
||||
});
|
||||
|
||||
app.listen(port, () => {
|
||||
console.log(`Server started at port ${port}`);
|
||||
});
|
||||
var httpServer = http.createServer(app);
|
||||
var httpsServer = https.createServer(credentials, app);
|
||||
|
||||
httpServer.listen(porthttp);
|
||||
if (process.env.PROD) {
|
||||
httpsServer.listen(port);
|
||||
}
|
||||
|
||||
//app.listen(port, () => {
|
||||
// console.log(`Server started at port ${port}`);
|
||||
//});
|
||||
|
||||
|
||||
module.exports = { app };
|
||||
|
||||
|
||||
Reference in New Issue
Block a user