-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
35 lines (29 loc) · 1010 Bytes
/
server.js
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
/* WEB SERVER FOR OAUTHv2 AUTHENTICATION */
console.log('Server-side code running');
/* REQUIRE FOR WEB SERVER & FILE MANAGEMENT */
const fs = require('fs');
const ip = require('ip');
const path = require('path');
const https = require('https');
const express = require('express');
//Using Express
const app = express();
const ipAddress = ip.address();
//Redirect HTTP to HTTPS
app.enable("trust proxy");
app.use(function(request, response, next) {
if (!request.secure) {
return response.redirect("https://" + request.headers.host + request.url);
}
next();
});
//Use the Public Directory
app.use(express.static('public'));
// SSL Certs
const httpsOptions = { key: fs.readFileSync('public/sslcert/key.pem'), cert: fs.readFileSync('public/sslcert/cert.pem') };
//Create Servers
app.listen(80);
https.createServer(httpsOptions, app).listen(443, function () {
console.log('Express HTTPS server listening on port ' + 443);
});
console.log('Express Server exposed on IP: ' + ipAddress);