-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
public.js
50 lines (39 loc) · 1011 Bytes
/
public.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import express from 'express';
import http from 'http';
import https from 'https';
import fs from 'fs';
import cors from 'cors';
const app = express();
// Certificate
const privateKey = fs.readFileSync('/etc/letsencrypt/live/nozaki.ninja/privkey.pem', 'utf8');
const certificate = fs.readFileSync('/etc/letsencrypt/live/nozaki.ninja/cert.pem', 'utf8');
const ca = fs.readFileSync('/etc/letsencrypt/live/nozaki.ninja/chain.pem', 'utf8');
const credentials = {
key: privateKey,
cert: certificate,
ca: ca
};
//Setting up Cors
app.use(cors());
// Setting up the public directory
app.use(
express.static(
'./',
{ dotfiles: 'allow' }
)
);
// Starting both http & https servers
const httpServer = http.createServer(app);
const httpsServer = https.createServer(credentials, app);
httpServer.listen(
80,
()=>{
console.log('HTTP Server running on port 80');
}
);
httpsServer.listen(
443,
()=>{
console.log('HTTPS Server running on port 443');
}
);