-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
29 lines (24 loc) · 832 Bytes
/
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
const path = require("path");
const express = require("express");
const bodyParser = require("body-parser");
const cors = require("cors");
const morgan = require("morgan");
require("dotenv").config();
const app = express();
const initMongoose = require("./init/mongoose");
const PATH_TO_FRONTEND_STATIC = path.join(__dirname, "../articles-app/build");
app.use(express.static("public"));
app.use(cors());
app.use(morgan("dev"));
app.use(express.static(PATH_TO_FRONTEND_STATIC));
app.use(bodyParser.json());
/* API ROUTES */
app.use("/api", require("./modules/api.routes"));
app.use("**", (req, res) => {
res.sendFile("index.html", { root: PATH_TO_FRONTEND_STATIC });
});
const PORT = process.env.PORT;
initMongoose();
app.listen(PORT, () => {
console.log(`Successfully started server on port http://localhost:${PORT}`);
});