· 4 years ago · Aug 19, 2021, 04:12 PM
1const express = require('express');
2const app = express();
3var fs = require('fs');
4var path = require('path');
5const port = process.env.PORT || 9999;
6const server = app.listen(port);
7console.log('running on port' , port)
8server.timeout = 1000 * 60 * 10; // 10 minutes
9
10// Use middleware to set the default Content-Type
11app.use(function (req, res, next) {
12 res.header('Content-Type', 'application/json');
13 next();
14});
15/////
16
17
18//var key1 = fs.readFileSync('key1.txt','utf8');
19//var key2 = fs.readFileSync('key2.txt','utf8');
20
21app.get('/', (req, res) => {
22 console.log(req)
23 res.send(Hello);
24})
25/////
26app.get('/capabilities', (req, res) => {
27 console.log(req)
28 res.send(JSON.stringify(
29 {
30 "entropy" : true,
31 "key" : true,
32 "algorithm": "QKD",
33 "localSystemID": "Alice",
34 "remoteSystemID": [
35 "Bob",
36 "Eve"
37 ]
38 }
39 ));
40})
41
42app.get('/entropy', (req, res) => {
43 console.log(req)
44 // Set Content-Type differently for this particular API
45 res.set({'Content-Type': 'application/json'});
46 res.send({
47 "randomStr" : "rfu839t",
48 "minentropy" : 128
49 }
50 );
51 })
52
53app.get('/key', (req, res) => {
54 console.log(req)
55 // Set Content-Type differently for this particular API
56 res.set({'Content-Type': 'application/json'});
57 var key1 = fs.readFileSync('key1.txt','utf8');
58 res.send({'keyid': key1}
59 );
60 })