-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapp.js
More file actions
30 lines (23 loc) · 771 Bytes
/
app.js
File metadata and controls
30 lines (23 loc) · 771 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
import express from "express";
import userRouter from "./routes/user.js";
import blogRouter from "./routes/blog.js";
import { config } from "dotenv";
import cookieParser from "cookie-parser";
import { errorMiddleware } from "./middlewares/error.js";
import cors from "cors";
export const app = express();
config({
path: "./data/config.env",
});
// Using Middlewares
app.use(express.json());
app.use(cookieParser());
app.use(cors({credentials: true, origin: 'http://localhost:3000',methods: ["GET", "POST", "PUT", "DELETE"]}));
// Using routes
app.use("/api/v1/users", userRouter);
app.use("/api/v1/blogs", blogRouter);
app.get("/", (req, res) => {
res.send("Nice working");
});
// Using Error Middleware
app.use(errorMiddleware);