-
Notifications
You must be signed in to change notification settings - Fork 107
/
Copy pathserver.js
40 lines (30 loc) · 1.02 KB
/
server.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
import cors from "cors";
import path from "path";
import express from "express";
import bodyParser from "body-parser";
import dotenv from "dotenv";
dotenv.config();
const app = express();
import users from "./controller/user.js";
import auth from "./controller/auth.js";
import movie from "./controller/movie.js";
import genre from "./controller/genre.js";
//To prevent CORS errors
app.use(cors());
// Body parser middleware
app.use(bodyParser.urlencoded({ extended: true, limit: "10mb" }));
app.use(bodyParser.json({ limit: "10mb" }));
//Connecting mongoDB
import "./utils/mongodb.js"; //Database
//App routes to handle requests
app.use("/api/movies", movie);
app.use("/api/genres", genre);
app.use("/api/users", users);
app.use("/api/auth", auth);
//Serve our static asset
app.use(express.static("frontend/build"));
app.get("*", (req, res) => {
res.sendFile(path.resolve(__dirname, "frontend", "build", "index.html"));
});
const port = process.env.PORT || 5000;
app.listen(port, () => console.log(`Server running on port ${port}`));