-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
46 lines (40 loc) · 1.21 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
41
42
43
44
45
46
const express = require("express");
const app = express();
const connectDB = require("./utils/connectDB");
const errorHandler = require("./middleware/errorHandler");
const cors = require("cors");
const path = require("path");
// spells
require("dotenv").config();
require("express-async-errors");
// routers
const bookmarkRoute = require("./routes/bookmark");
const userRoute = require("./routes/user");
const authenticate = require("./middleware/authorization");
const notFound = require("./middleware/not-found");
// cors
const corOptions = {
origin: "https://bookmarks-by-manpreet.netlify.app",
optionsSuccessStatus: 200,
};
app.use(cors(corOptions));
app.use(express.json());
app.use("/user", userRoute);
app.use("/bookmark", bookmarkRoute);
//
// app.use(express.static("client/bookmark/build")); // set static folder
// app.get("*", (req, res) => {
// res.sendFile(
// path.resolve(__dirname, "client", "bookmark", "build", "index.html")
// );
// });
app.use(notFound);
app.use(errorHandler);
const port = process.env.PORT || 5000;
const startServer = async () => {
await connectDB(process.env.MONGO_URI);
app.listen(port, () => {
console.log(`Server started on port ${port}`);
});
};
startServer();