-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdev-server.ts
More file actions
59 lines (49 loc) · 1.28 KB
/
dev-server.ts
File metadata and controls
59 lines (49 loc) · 1.28 KB
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
53
54
55
56
57
58
59
import "reflect-metadata";
import dotenv from "dotenv";
import express, { Request, Response } from "express";
import { ApolloServer } from "apollo-server-express";
import { buildSchema } from "type-graphql";
import cors from "cors";
import { createConnection } from "./src/server/db";
import { getQuotes } from "./src/server/utils/getQuotes";
import RatingResolver from "./src/server/resolvers/rating";
import { Context } from "./src/types";
dotenv.config();
type DevServerContext = Omit<Context, "req" | "res"> & {
req: Request;
res: Response;
};
const main = async () => {
await createConnection();
const app = express();
app.set("trust proxy", 1);
app.use(
cors({
origin: "http://localhost:3000",
credentials: true,
})
);
const apolloServer = new ApolloServer({
schema: await buildSchema({
resolvers: [RatingResolver],
validate: false,
emitSchemaFile: true,
}),
context: ({ req, res }): DevServerContext => ({
req,
res,
getUserId: async () => process.env.DEV_SERVER_USER_ID!,
getQuotes,
}),
});
apolloServer.applyMiddleware({
app,
cors: false,
});
app.listen(4000, () => {
console.log("server started on http://localhost:4000");
});
};
main().catch((err) => {
console.error(err);
});