server.js 939 Bytes
Newer Older
Patrick's avatar
Patrick committed
1
// Dependencies
Patrick's avatar
Patrick committed
2
const fs = require('fs');
Patrick's avatar
Patrick committed
3
4
5
const http = require('http');
const https = require('https');
const express = require('express');
Patrick's avatar
Patrick committed
6

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

// 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
Patrick committed
20
21
22
app.use((req, res) => {
	res.send('Hello there !');
});
Patrick's avatar
Patrick committed
23

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

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

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