Stackedit/index.js

37 lines
1.1 KiB
JavaScript
Raw Normal View History

2018-01-04 20:19:10 +00:00
const env = require('./config/prod.env');
if (!process.env.NODE_ENV) {
process.env.NODE_ENV = JSON.parse(env.NODE_ENV);
}
if (!process.env.GOOGLE_CLIENT_ID) {
process.env.GOOGLE_CLIENT_ID = JSON.parse(env.GOOGLE_CLIENT_ID);
}
2017-09-27 20:27:12 +00:00
2017-09-30 12:01:29 +00:00
const http = require('http');
const https = require('https');
const path = require('path');
const express = require('express');
const fs = require('fs');
const app = express();
2017-09-26 22:54:26 +00:00
2017-09-29 18:43:26 +00:00
require('./server')(app, process.env.SERVE_V4);
2017-09-26 22:54:26 +00:00
2017-09-30 12:01:29 +00:00
let port = parseInt(process.env.PORT || 8080, 10);
if (port === 443) {
const credentials = {
key: fs.readFileSync(path.join(__dirname, 'ssl.key'), 'utf8'),
cert: fs.readFileSync(path.join(__dirname, 'ssl.crt'), 'utf8'),
ca: fs.readFileSync(path.join(__dirname, 'ssl.ca'), 'utf8').split('\n\n'),
};
const httpsServer = https.createServer(credentials, app);
httpsServer.listen(port, null, () => {
console.log('HTTPS server started: https://localhost');
});
port = 80;
2017-09-26 22:54:26 +00:00
}
2017-09-30 12:01:29 +00:00
const httpServer = http.createServer(app);
httpServer.listen(port, null, () => {
console.log(`HTTP server started: http://localhost:${port}`);
2017-09-26 22:54:26 +00:00
});