server.js 923 Bytes
Newer Older
Patrick's avatar
Patrick committed
1

Patrick's avatar
test    
Patrick committed
2
3
4
5
const fs = require('fs');
const http = require('http');
const https = require('https');
const express = require('express');
Patrick's avatar
Patrick committed
6

Patrick's avatar
test    
Patrick committed
7
const app = express();
Patrick's avatar
Patrick committed
8
9
10
11
12
13
14
15
16
17
18

// Certificate
const privateKey = fs.readFileSync('/etc/letsencrypt/live/umfrage.smartvillages.online/privkey.pem', 'utf8');
const certificate = fs.readFileSync('/etc/letsencrypt/live/umfrage.smartvillages.online/cert.pem', 'utf8');
const ca = fs.readFileSync('/etc/letsencrypt/live/umfrage.smartvillages.online/chain.pem', 'utf8');
const credentials = {
	key: privateKey,
	cert: certificate,
	ca: ca
};

Patrick's avatar
test    
Patrick committed
19
20
21
app.use((req, res) => {
	res.send('Hello there !');
});
Patrick's avatar
Patrick committed
22

Patrick's avatar
Patrick committed
23
24
25
26
// Starting both http & https servers
const httpServer = http.createServer(app);
const httpsServer = https.createServer(credentials, app);

Patrick's avatar
test    
Patrick committed
27
28
httpServer.listen(8083, () => {
	console.log('HTTP Server running on port 80');
Patrick's avatar
Patrick committed
29
30
});

Patrick's avatar
test    
Patrick committed
31
32
33
httpsServer.listen(8084, () => {
	console.log('HTTPS Server running on port 443');
});