-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
55 lines (50 loc) · 1.52 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
53
54
55
import "tsconfig-paths/register";
import express from "express";
import { ApolloServer } from "apollo-server-express";
import { sessionMiddleware, corsOptions } from "@config/server-config";
import { schema } from "./schema";
import { pingDB } from "@utils/pingDB";
import { checkEnv, currentEnv } from "@config/environment";
import helmet from "helmet";
import passport from "passport";
import compression from "compression";
import depthLimit from "graphql-depth-limit";
import morgan from "morgan";
import cors from "cors";
import * as loaders from "src/dataloaders/index";
import "./config/passport-config";
const app = express();
checkEnv() &&
(async () => {
app.use(cors(corsOptions));
app.use(helmet());
app.use(morgan("short"));
app.use(compression());
app.use(sessionMiddleware());
app.use(passport.initialize());
app.use(passport.session());
pingDB().then((res) => {
res.isConnected
? console.log("Connected to db!")
: console.log(res.message);
});
const server = new ApolloServer({
subscriptions: false,
introspection: currentEnv !== "PROD",
playground: currentEnv !== "PROD",
schema,
validationRules: [depthLimit(5)],
context: ({ req, res }) => {
return {
req,
res,
loaders,
};
},
});
server.applyMiddleware({ app });
app.listen(process.env.PORT, () =>
console.log(`🚀 --- :${process.env.PORT}`)
);
app.use("/", require("./src/routes/maintenance"));
})();