-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
48 lines (39 loc) · 1.45 KB
/
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
36
37
38
39
40
41
42
43
44
45
46
47
48
const bodyParser = require("body-parser");
const cors = require("cors");
const express = require("express");
const fs = require("fs");
const http = require("http");
const https = require("https")
const sequelize = require("./models/index.js");
const views = __dirname + '/views/';
const app = express();
app.use(cors());
app.use(express.static(__dirname, { dotfiles: 'allow' }));
app.use(express.static(views));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
sequelize.sync();
app.get('/', function (req,res) {
res.sendFile(path + "index.html");
});
require("./routes/document.routes")(app);
require("./routes/project.routes")(app);
require("./routes/user.routes")(app);
const chain = "/etc/letsencrypt/live/nostromoxpart.com/chain.pem";
const cert = "/etc/letsencrypt/live/nostromoxpart.com/cert.pem";
const privkey = "/etc/letsencrypt/live/nostromoxpart.com/privkey.pem";
var options = {
ca: fs.readFileSync(chain, 'utf8'),
cert: fs.readFileSync(cert, 'utf8'),
key: fs.readFileSync(privkey, 'utf8')
}
setTimeout(function () {serverSecure.setSecureContext({
ca: fs.readFileSync(chain, 'utf8'),
cert: fs.readFileSync(cert, 'utf8'),
key: fs.readFileSync(privkey, 'utf8')
})},86400000)
const serverSecure = https.createServer(options, app).listen(443);
const server = http.createServer(function (req, res) {
res.writeHead(301, { "Location": "https://" + req.headers['host'] + req.url });
res.end();
}, app).listen(80);