-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
52 lines (44 loc) · 1.34 KB
/
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
const pug = require('pug');
const express = require('express');
const fs = require("fs");
const https = require("https");
const port = process.env.PORT || 8080;
const options = {
key: fs.readFileSync(`${__dirname}/certs/cs/server-key.pem`),
cert: fs.readFileSync(`${__dirname}/certs/cs/server-crt.pem`),
ca: [
fs.readFileSync(`${__dirname}/certs/cs/client-ca-crt.pem`)
],
// Requesting the client to provide a certificate, to authenticate.
requestCert: true,
// As specified as "true", so no unauthenticated traffic
// will make it to the specified route specified
rejectUnauthorized: true
};
// Load mock data
const data = JSON.parse(fs.readFileSync(__dirname + "/data/" + "data.json", 'utf8'));
const app = express();
app.set('view engine', 'pug');
app.get('/', function (req, res) {
try {
res.render('server', { });
} catch (error) {
console.log(error);
res.render('error', { message: error });
}
});
app.get('/api', function(req,res) {
res.send('"OK!');
});
app.get('/api/feds', function (req, res) {
res.end(JSON.stringify(data.federators, null, 2));
})
app.get('/api/crl', function (req, res) {
res.end(JSON.stringify(data.crl, null, 2));
})
app.get('/api/batches/:id', function (req, res) {
res.end(JSON.stringify(data.batches[req.params.id], null, 2));
})
https
.createServer(options, app)
.listen(port);