-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.js
67 lines (54 loc) · 1.66 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
let httpPort = 80;
let httpsPort = 443
const http = require('http');
const https = require('https');
const fs = require('fs');
const express = require('express');
const index = fs.readFileSync('./index.html', 'utf-8');
const example = fs.readFileSync('./example.html', 'utf-8');
const output = fs.readFileSync('./output.html', 'utf-8');
const app = express();
const highlight = require('./highlight');
// Check on security/certificate stuff
let privateKey;
let certificate;
let credentials;
if (fs.existsSync('./certs/key.pem') && fs.existsSync('./certs/cert.pem')) {
privateKey = fs.readFileSync('./certs/key.pem', 'utf-8');
certificate = fs.readFileSync('./certs/cert.pem', 'utf-8');
credentials = {key: privateKey, cert: certificate};
}
// Express app setup
app.use(express.json());
app.use(express.urlencoded({ extended: true }))
app.use('/assets', express.static('assets'));
app.use('/examples', express.static('examples'));
app.use('/colors.css', express.static('colors.css'));
app.get(['/', '/index.html'], (req, res) => {
res.send(index);
});
app.get(['/example'], (req, res) => {
res.send(example);
});
app.get(['/output'], (req, res) => {
res.send(output);
});
app.post('/data', async (req, res) => {
res.send(await highlight(req.body.cda, req.body.fhir));
})
/*
app.get('*', (req, res) => {
res.redirect('/');
});
*/
var httpServer = http.createServer(app);
let httpsServer;
if (credentials) {
httpsServer = https.createServer(credentials, app);
}
httpServer.listen(httpPort);
console.log(`HTTP server running on port ${httpPort}...`);
if (httpsServer) {
httpsServer.listen(httpsPort);
console.log(`HTTPS server running on port ${httpsPort}...`);
}