server.js 1.29 KB
Newer Older
Patrick's avatar
test    
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
const bodyParser = require('body-parser')
Patrick's avatar
test    
Patrick committed
7

Patrick's avatar
Patrick committed
8
9
const request = require('ajax-request');

Patrick's avatar
test    
Patrick committed
10

Patrick's avatar
test    
Patrick committed
11
const app = express();
Patrick's avatar
Patrick committed
12
13
14
15
16
17
app.all('*', function(req, res, next) {
	res.header('Access-Control-Allow-Origin', '*');
	res.header('Access-Control-Allow-Methods', 'PUT, GET, POST, DELETE, OPTIONS');
	res.header('Access-Control-Allow-Headers', 'Content-Type');
	next();
  });
Patrick's avatar
test    
Patrick committed
18
19
app.use(bodyParser.urlencoded({ extended: false })) 
app.use(bodyParser.json())
Patrick's avatar
Patrick committed
20
21
22
23
// 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');
Patrick's avatar
test    
Patrick committed
24

Patrick's avatar
Patrick committed
25
26
27
28
29
30
const credentials = {
	key: privateKey,
	cert: certificate,
	ca: ca
};

Patrick's avatar
test    
Patrick committed
31
app.use(express.static('vcm'));
Patrick's avatar
Patrick committed
32

Patrick's avatar
Patrick committed
33
// Starting both http & https servers
Patrick's avatar
Patrick committed
34
// const httpServer = http.createServer(app);
Patrick's avatar
Patrick committed
35
36
const httpsServer = https.createServer(credentials, app);

Patrick's avatar
Patrick committed
37
38
39
// httpServer.listen(8083, () => {
// 	console.log('HTTP Server running on port 80');
// });
Patrick's avatar
test    
Patrick committed
40

Patrick's avatar
Patrick committed
41
httpsServer.listen(8086 , () => {
Patrick's avatar
Patrick committed
42
	console.log('HTTPS Server running on port 8084');
Patrick's avatar
Patrick committed
43
44
});