-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
31 lines (28 loc) · 1000 Bytes
/
server.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
//server.js
const express = require('express');
const favicon = require('express-favicon');
const path = require('path');
var https = require('https');
var http = require('http');
var fs = require('fs');
// This line is from the Node.js HTTPS documentation.
var options = {
key: fs.readFileSync('/etc/cert/key.pem'),
cert: fs.readFileSync('/etc/cert/cert.pem')
};
// Create a service (the app object is just a callback).
var app = express();
app.use(favicon(__dirname + '/dist/favicon.ico'));
// the __dirname is the current directory from where the script is running
app.use(express.static(__dirname));
app.use(express.static(path.join(__dirname, 'dist')));
app.get('/ping', function(req, res) {
return res.send('pong');
});
app.get('/*', function(req, res) {
res.sendFile(path.join(__dirname, 'dist', 'index.html'));
});
// Create an HTTP service.
http.createServer(app).listen(80);
// Create an HTTPS service identical to the HTTP service.
https.createServer(options, app).listen(443);