-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
40 lines (28 loc) · 961 Bytes
/
app.js
File metadata and controls
40 lines (28 loc) · 961 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
import express from "express";
import dotenv from "dotenv";
import dbConnect from "./config/dbConnect.js";
import userRoute from "./routes/userroute.js";
import bodyparser from "body-parser";
import morgan from "morgan";
import cors from "cors";
import essentialsRoute from "./routes/essentialsroute.js";
dotenv.config({path:'./.env'});
const app = express();
//app.use(cors());
dbConnect();
// log requests
app.use(
cors({
credentials: true,
origin: true,
allowedHeaders: ["Origin", "X-Requested-With", "Content", "Accept", "Content-Type", "Authorization"],
methods: ["GET", "POST", "PUT", "DELETE", "PATCH", "OPTIONS"]
})
);
app.use(morgan('tiny'));
app.use(express.json());
app.use(bodyparser.urlencoded({ extended : true}))
app.use("/api/v1/users", userRoute);
app.use("/api/v1/essentials", essentialsRoute);
const PORT = process.env.PORT || 7007
app.listen(PORT,console.log(`Server is running at ${PORT}`))