-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
38 lines (32 loc) · 1.03 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
import express from "express";
import cors from "cors";
import cookieParser from "cookie-parser";
import { connectDb } from "./db/db.js";
import { errorHandler, notFound } from "./middleware/errorMiddleware.js";
//Importing Routes
import userRoutes from "./routes/user.router.js";
import genAiRoute from "./routes/geminiai.router.js";
import paymentRoutes from "./routes/payment.route.js";
connectDb(); //Database
const port = process.env.PORT || 6000;
//Express Initialized
const app = express();
//Middlewares
app.use(express.json());
app.use(cors({ origin: process.env.FRONTEND_URL, credentials: true }));
app.use(cookieParser());
//Routes
app.use("/api/v1/user", userRoutes);
app.use("/api/v1/ai", genAiRoute);
app.use("/api/v1/payment", paymentRoutes);
//Main route
app.get("/", (req, res) => {
res.status(200).json({ message: "Welcome to AI Content Genrator Server" });
});
//Middlewares-Custom
app.use(notFound);
app.use(errorHandler);
//Server Start
app.listen(port, () => {
console.log(`Server running on http://localhost:${port}`);
});