김태영

update running server

Showing 1 changed file with 16 additions and 4 deletions
...@@ -6,26 +6,38 @@ ...@@ -6,26 +6,38 @@
6 6
7 var app = require('../app'); 7 var app = require('../app');
8 var debug = require('debug')('2020-02-oss-termproject:server'); 8 var debug = require('debug')('2020-02-oss-termproject:server');
9 -var http = require('http'); 9 +const domain = "www.khumwd.ml"
10 +const sslport = 8080;
11 +
12 +const fs = require('fs');
13 +const path = require('path');
14 +const HTTPS = require('https');
10 15
11 /** 16 /**
12 * Get port from environment and store in Express. 17 * Get port from environment and store in Express.
13 */ 18 */
14 19
15 -var port = normalizePort(process.env.PORT || '3000'); 20 +var port = normalizePort(process.env.PORT || '8080');
16 app.set('port', port); 21 app.set('port', port);
17 22
18 /** 23 /**
19 * Create HTTP server. 24 * Create HTTP server.
20 */ 25 */
21 26
22 -var server = http.createServer(app); 27 +const option = {
28 + ca: fs.readFileSync('/etc/letsencrypt/live/' + domain +'/fullchain.pem'),
29 + key: fs.readFileSync(path.resolve(process.cwd(), '/etc/letsencrypt/live/' + domain +'/privkey.pem'), 'utf8').toString(),
30 + cert: fs.readFileSync(path.resolve(process.cwd(), '/etc/letsencrypt/live/' + domain +'/cert.pem'), 'utf8').toString(),
31 +};
32 +
33 +var server = HTTPS.createServer(option, app).listen(sslport, () => {
34 + console.log(`[HTTPS] Server is started on port ${sslport}`);
35 +});
23 36
24 /** 37 /**
25 * Listen on provided port, on all network interfaces. 38 * Listen on provided port, on all network interfaces.
26 */ 39 */
27 40
28 -server.listen(port);
29 server.on('error', onError); 41 server.on('error', onError);
30 server.on('listening', onListening); 42 server.on('listening', onListening);
31 43
......