-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
44 lines (32 loc) · 931 Bytes
/
server.js
File metadata and controls
44 lines (32 loc) · 931 Bytes
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
import dotenv from "dotenv";
dotenv.config();
import connectDB from "./config/db.js";
connectDB();
var allowCrossDomain = function (req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Methods", "GET,PUT,POST,DELETE,OPTIONS");
res.header(
"Access-Control-Allow-Headers",
"Content-Type, Authorization, Content-Length, X-Requested-With"
);
// intercept OPTIONS method
if ("OPTIONS" == req.method) {
res.send(200);
} else {
next();
}
};
import express from "express";
import commentRoutes from "./routes/commentRoutes.js";
const app = express();
const PORT = process.env.PORT || 5000;
app.use(express.json());
app.use(allowCrossDomain);
app.listen(
PORT,
console.log(`Server running in ${process.env.NODE_ENV} mode on port ${PORT}`)
);
app.get("/", (req, res) => {
res.send("API is running");
});
app.use("/api/comments", commentRoutes);