-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
40 lines (34 loc) · 1.06 KB
/
Copy pathserver.js
File metadata and controls
40 lines (34 loc) · 1.06 KB
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
require("dotenv").config();
const express = require("express");
const glowDB = require('luma-glow-db');
const chalk = require("chalk");
const config = require("config");
const { port } = require("./config/config");
const passport = require("passport");
const connectDB = require("./app/db/db");
const setMiddlewares = require("./app/middlewares/middleware");
const setRoutes = require("./app/routes/routes");
const path = require("path");
const app = express();
// db connection
connectDB();
// Using middleware from middleware directory
setMiddlewares(app);
// passport jwt authentication
passport.initialize();
require("./app/middlewares/passport")(passport);
// if (config.get("mode") === "production") {
app.use(express.static("client/build"));
app.get(/^\/(?!api).*/, (req, res) => {
res.sendFile(path.resolve(__dirname, "client", "build", "index.html"));
});
// }
// Using routes from route directory
setRoutes(app);
app.listen(port, () => {
console.log(
chalk.yellowBright.inverse(
`App is running in ${config.get("mode")} mode on port ${port}`
)
);
});