forked from jddamore/IPSviewer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
49 lines (40 loc) · 1.33 KB
/
app.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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
const http = require('http');
const https = require('https');
const fs = require('fs');
const express = require('express');
const index = fs.readFileSync('./ips_view.html', 'utf-8');
const favicon = fs.readFileSync('./favicon.ico');
const app = express();
let privateKey;
let certificate;
let ca;
let credentials;
if (fs.existsSync('./certs/ipsviewer.key') && fs.existsSync('./certs/ipsviewer.crt') && fs.existsSync('./certs/ipsviewer.ca-bundle') ) {
privateKey = fs.readFileSync('./certs/ipsviewer.key', 'utf-8');
certificate = fs.readFileSync('./certs/ipsviewer.crt', 'utf-8');
ca = fs.readFileSync('./certs/ipsviewer.ca-bundle', 'utf-8')
credentials = {key: privateKey, cert: certificate, ca: ca};
}
app.use('/templates', express.static('templates'));
app.use('/samples', express.static('samples'));
app.use('/assets', express.static('assets'));
app.get(['/favicon.ico'], (req, res) => {
res.send(favicon);
});
app.get(['/', '/index.html'], (req, res) => {
res.send(index);
});
app.get('*', (req, res) => {
res.redirect('/');
});
var httpServer = http.createServer(app);
let httpsServer;
if (credentials) {
httpsServer = https.createServer(credentials, app);
}
httpServer.listen(80);
if (httpsServer) {
httpsServer.listen(443);
console.log('listening on HTTP and HTTPS...')
}
else console.log('HTTPS server not running...')