-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
52 lines (45 loc) · 1.22 KB
/
index.ts
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
45
46
47
48
49
50
51
52
import "dotenv/config";
import cors from "cors";
import express from "express";
import { apolloServer } from "./server";
import cookieParser from "cookie-parser";
import { PrismaClient } from "@prisma/client";
import { refreshRoute } from "./utils/refreshRoute";
import { defaultRoute } from "./utils/defaultRoute";
import { healthRoute } from "./utils/healthRoute";
export const prisma = new PrismaClient();
const corsOptions: cors.CorsOptions = {
credentials: true,
origin: [
"https://studio.apollographql.com",
"https://xkart.vercel.app/",
"http://127.0.0.1:5173",
"http://localhost:5173",
],
};
async function main() {
const app = express();
app.use(express.json());
app.use(cookieParser());
app.use(cors(corsOptions));
app.get("/", defaultRoute);
app.post("/refresh", refreshRoute);
app.post("/health", healthRoute);
await apolloServer.start();
apolloServer.applyMiddleware({
app,
cors: corsOptions,
});
app.listen(process.env.PORT! || 8080, () => {
console.log("Server Connected (❁´◡`❁)");
});
}
main()
.then(async () => {
await prisma.$disconnect();
})
.catch(async (e) => {
console.error(e);
await prisma.$disconnect();
process.exit(1);
});