-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
executable file
·123 lines (102 loc) · 3.14 KB
/
index.js
File metadata and controls
executable file
·123 lines (102 loc) · 3.14 KB
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
const fs = require('fs');
const express = require('express');
const solid = require('solid-server');
const path = require('path');
const config = require('./config');
const logging = require('./middleware/logging');
const PORT = process.env.PORT || 8443;
const logger = logging.logger;
const https = require('https');
const hbs = require('express-handlebars');
// Ignore error if self signed certificate
process.env.NODE_TLS_REJECT_UNAUTHORIZED = 0;
// Starting our express app
const app = express();
// Init winston logger
app.use(logging.expressWinston);
// Static files
app.use("/static", express.static('static'));
app.use(express.static(__dirname));
// Set handlebars template engine
app.engine('.hbs', hbs({
extname: '.hbs',
layoutsDir: 'views/base',
defaultLayout: 'base'
}));
app.set('view engine', '.hbs');
// **************************************
// My routes
// **************************************
app.get('/doctore', function (req, res) {
logger.info(req);
let context = {
patients: [
'Luka',
'Jan',
'Bob',
],
title: "First Post",
story:
{
intro: "Before the jump",
body: "After the jump"
}
};
res.render('doctor', context);
});
app.get('/patiente', function (req2, res2) {
logger.info("GER REQ");
const options = {
host: 'https://patient4.example.com',
path: '/health',
port:8443
};
const url = options.host + options.path;
// let req = https.get(options, function(res) {
// console.log('STATUS: ' + res.statusCode);
// console.log('HEADERS: ' + JSON.stringify(res.headers));
//
// // Buffer the body entirely for processing as a whole.
// var bodyChunks = [];
// res.on('data', function(chunk) {
// // You can process streamed parts here...
// bodyChunks.push(chunk);
// }).on('end', function() {
// var body = Buffer.concat(bodyChunks);
// console.log('BODY: ' + body);
// // ...and/or process the entire body here.
// })
// });
const options2 = {
host: 'https://patient4.example.com',
path: '/health',
port: 8443
};
https.get('https://lukatavcer.example.com:8443/private/health/', (resp) => {
let data = '';
// A chunk of data has been recieved.
resp.on('data', (chunk) => {
data += chunk;
});
// The whole response has been received. Print out the result.
resp.on('end', () => {
console.log(JSON.parse(data).explanation);
});
}).on("error", (err) => {
console.log("Error: " + err.message);
});
res2.send('patient');
});
// Mount Solid on /
const ldp = solid(config);
app.use('/', ldp);
// const http = require('http')
// var httpServer = http.createServer(app);
// httpServer.listen(3000);
// Starting server
const credentials = {
key: fs.readFileSync(config.sslKey, 'utf8'),
cert: fs.readFileSync(config.sslCert, 'utf8')
};
const httpsServer = https.createServer(credentials, app);
httpsServer.listen(PORT);