-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
executable file
·45 lines (38 loc) · 1.25 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
const express = require("express");
const bodyParser = require("body-parser");
const mysql = require("mysql");
const https = require("https");
const fs = require("fs");
const app = express();
app.use(bodyParser.urlencoded({ extended: true }));
// database settings
const db = mysql.createConnection({
host: process.env.MYSQL_HOST,
user: process.env.MYSQL_USER,
password: process.env.MYSQL_PASSWORD,
database: process.env.MYSQL_DATABASE
});
// connect to database
db.connect((err) => {
if (err) {
throw err;
}
console.log("Connected to database");
});
global.db = db;
require("./routes/main")(app);
// import bootstrap
app.use('/css', express.static(__dirname + '/node_modules/bootstrap/dist/css'));
app.set("views", __dirname + "/views");
app.set("view engine", "ejs");
app.engine("html", require("ejs").renderFile);
// SSL certificate options
const options = {
key: fs.readFileSync(process.env.SSL_ROUTE_PRIV_KEY),
cert: fs.readFileSync(process.env.SSL_ROUTE_PUBLIC_KEY),
};
// create HTTPS server
https.createServer(options, app).listen(process.env.WEBAPP_SERVER_PORT, () => {
console.log(`App listening on port ${process.env.WEBAPP_SERVER_PORT}!`);
console.log(`Please go to https://localhost:${process.env.WEBAPP_SERVER_PORT}/home`);
});