-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
59 lines (50 loc) · 1.65 KB
/
index.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
51
52
53
54
55
56
57
58
59
require('dotenv').config();
const express = require('express');
const session = require('express-session');
const https = require('https');
const path = require('path');
const fs = require('fs');
const cors = require('cors');
const database = require('./src/utils/database');
const app = express();
var corsOptions = {
credentials: true,
origin: function(origin, callback) {
callback(null, true);
}
}
app.use(cors(corsOptions));
app.use('/',express.static('client'));
app.use('/admin',express.static('admin-panel/build'));
app.use(express.json());
app.use(session({
secret: 'UBYVF*^&GUVYIF*GEUO',
resave: true,
saveUninitialized: true,
cookie: {httpOnly: true, maxAge: 60*60*1000 },
}))
app.use('/drink', require('./src/routes/drink.route'));
app.use('/category', require('./src/routes/category.route'));
app.use('/auth', require('./src/routes/auth.route'));
database.run();
if (process.env.CERT_LOCATION) {
var http = express();
http.get('*', function (req, res) {
res.redirect("https://" + req.headers.host + req.url);
});
http.listen(80);
var key = fs.readFileSync(process.env.CERT_LOCATION + "/privkey.pem");
var cert = fs.readFileSync(process.env.CERT_LOCATION + "/cert.pem");
var bundle = fs.readFileSync(process.env.CERT_LOCATION + "/chain.pem");
var options = {
key: key,
cert: cert,
ca: bundle
};
var server = https.createServer(options, app);
server.listen(443, () => {
console.log("Express server started listening on port " + 443);
});
} else {
app.listen(80);
}