-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
43 lines (35 loc) · 1.15 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
const express = require("express");
const path = require("path");
// Handle all err messages instead of using try/catch blocks
require("express-async-errors");
// Calling variuos app.use in separate file
const app = express();
// Includes dotenv and Morgan
require("./startup/config")(app);
// Include connection to database
require("./startup/db")();
// Joi validation
require("./startup/validation")();
// Helmet and compress
require("./startup/prod")(app);
// Includes unhandled rejections and uncaught exceptions
require("./startup/logging")();
// Routes
require("./startup/routes")(app);
// Complete passport auth logic
require("./startup/auth")(app);
// Serve static assets if in production
if (process.env.NODE_ENV === "production") {
//*Set static folder up in production
app.use(express.static("client/build"));
app.get("*", (req, res) =>
res.sendFile(path.resolve(__dirname, "client", "build", "index.html"))
);
}
const port = process.env.PORT || 8000;
const server = app.listen(port, () =>
console.log(`Listening on port ${port}...`)
);
console.log(`We are currently in ${process.env.NODE_ENV}...`);
exports.app = app;
exports.server = server;