mirror of
https://gitee.com/mafgwo/stackedit
synced 2024-11-16 03:32:40 +08:00
36 lines
1.0 KiB
JavaScript
36 lines
1.0 KiB
JavaScript
const env = require('./config/prod.env');
|
|
|
|
Object.keys(env).forEach((key) => {
|
|
if (!process.env[key]) {
|
|
process.env[key] = JSON.parse(env[key]);
|
|
}
|
|
});
|
|
|
|
const http = require('http');
|
|
const https = require('https');
|
|
const path = require('path');
|
|
const express = require('express');
|
|
const fs = require('fs');
|
|
|
|
const app = express();
|
|
|
|
require('./server')(app, process.env.SERVE_V4);
|
|
|
|
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;
|
|
}
|
|
const httpServer = http.createServer(app);
|
|
httpServer.listen(port, null, () => {
|
|
console.log(`HTTP server started: http://localhost:${port}`);
|
|
});
|