Skip to content

Commit 22180b6

Browse files
committed
cors added
1 parent 99c75e4 commit 22180b6

4 files changed

Lines changed: 37 additions & 6 deletions

File tree

index.js

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,36 @@
11
const express = require("express");
2-
const { PORT } = require("./src/config/server.config");
2+
const { PORT, FRONTEND_URL } = require("./src/config/server.config");
33
const { appRouter } = require("./src/routes");
44
const errorHandler = require("./src/utils/errorHandler");
55
const connectDB = require("./src/config/db.config");
66
const cookieparser = require("cookie-parser");
7-
require("./src/queue/worker")
7+
const cors = require("cors");
8+
9+
require("./src/queue/worker");
810

911
const app = express();
1012

1113
app.use(cookieparser());
1214
app.use(express.json());
1315
app.use(express.urlencoded({ extended: true }));
14-
16+
app.use(
17+
cors({
18+
origin: ["http://localhost:3000", FRONTEND_URL],
19+
credentials: "include",
20+
})
21+
);
1522
app.use("/api", appRouter);
1623

1724
app.get("/", (req, res) => {
1825
res.status(200).send("server is running");
1926
});
2027

21-
2228
app.use(errorHandler);
2329

2430
connectDB()
2531
.then(() => {
2632
console.log("Connected to MongoDB");
27-
app.listen(PORT,async () => {
33+
app.listen(PORT, async () => {
2834
console.log(`Server is running on port ${PORT}`);
2935
});
3036
})

package-lock.json

Lines changed: 23 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
"bcrypt": "^6.0.0",
2727
"bullmq": "^5.56.4",
2828
"cookie-parser": "^1.4.7",
29+
"cors": "^2.8.5",
2930
"dotenv": "^17.0.0",
3031
"express": "^5.1.0",
3132
"http-status-codes": "^2.3.0",
@@ -53,4 +54,4 @@
5354
"nodemon": "^3.1.10",
5455
"prettier": "^3.6.2"
5556
}
56-
}
57+
}

src/config/server.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,5 @@ module.exports = {
1111
SMTP_SERVICE: process.env.SMTP_SERVICE,
1212
SMTP_MAIL: process.env.SMTP_MAIL,
1313
SMTP_PASSWORD: process.env.SMTP_PASSWORD,
14+
FRONTEND_URL: process.env.FRONTEND_URL,
1415
};

0 commit comments

Comments
 (0)