-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.ts
More file actions
53 lines (45 loc) · 1.53 KB
/
Copy pathserver.ts
File metadata and controls
53 lines (45 loc) · 1.53 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
import express from "express";
import {ApolloServer} from "apollo-server-express"
import depthLimit from "graphql-depth-limit"
import {createServer} from 'http'
import * as bodyParser from 'body-parser'
import compression from 'compression'
import cors from 'cors'
import Cookies from "cookies";
import schema from './schema'
import { userRouter } from "./lib/routes";
import { UserService } from "./middleware/auth";
import { modelAssociation } from "./lib/config/models/modelReletionships";
import {PlanCronJob} from "./lib/cronJobs/";
import { Mailer } from "./lib/mail/config";
const app = express()
const server = new ApolloServer({
schema,
validationRules: [depthLimit(7)],
context: async ({req, res} ) => {
const cookies = new Cookies(req, res)
const token = cookies.get("auth_token")
console.log('token>>>>', token);
const user = await new UserService().verifyToken(token!)
return {req,res, user, cookies }
}
});
var corsOptions = {
origin: 'http://localhost:3000',
credentials: true // <-- REQUIRED backend setting
};
app.use(cors(corsOptions));
app.use(bodyParser.json())
app.use(bodyParser.urlencoded({ extended: true }))
// app.use("*", cors());
app.use(compression());
app.use('/', userRouter);
modelAssociation()
server.applyMiddleware({app, path: "/graphql", cors: false});
const httpServer = createServer(app);
// PlanCronJob()
httpServer.listen(
{port: 8000},
(): void => console.log(`\n GraphQL server is now running
on http://localhost:8000/graphql`)
)