-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
45 lines (39 loc) · 1.18 KB
/
app.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
/* require dependencies */
const express = require("express");
const path = require("path");
const dotenv = require("dotenv").config();
const { sequelize } = require("./database");
const router = require("./routes");
const cookieParser = require("cookie-parser");
const cors = require("cors");
const logger = require("./logger");
/* important inits */
const app = express();
PORT = process.env.PORT;
HOSTNAME = process.env.HOSTNAME;
/* middlewares */
app.use(cookieParser());
app.use(express.static(path.join(__dirname, "public", "dist")));
app.use(express.static(path.join(__dirname, "public")));
app.use(express.json());
app.use(cors({
origin: process.env.ORIGIN,
credentials: true
}));
/* router setup */
app.use("/", router);
/* app boilerplate */
(async function checkDBConnection() {
try {
await sequelize.authenticate();
console.log('Connection to postgres has been established successfully.');
} catch (error) {
console.error('Unable to connect to the database:', error);
}
})();
process.on('uncaughtException', function (err) {
logger.log(err);
});
app.listen(PORT, HOSTNAME, () => {
console.log(`App is listening on port ${PORT}.`);
});