-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
87 lines (79 loc) · 2.15 KB
/
index.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
const { ApolloServer } = require('apollo-server-express');
const { importSchema } = require('graphql-import');
const express = require('express');
const session = require('express-session');
const MongoStore = require('connect-mongo');
const mongoose = require('mongoose');
const cookieParser = require('cookie-parser');
const path = require('path');
const mutation = require('./graphql/mutation');
const query = require('./graphql/query');
const app = express();
const { createDB, models } = require('./db');
const typeDefs = require('./graphql/typeDefs');
app.use(cookieParser());
app.set('trust proxy', 1);
app.use(
session({
secret: 'foo',
name: 'kanbanid',
resave: true,
saveUninitialized: false,
cookie: {
sameSite: process.env.NODE_ENV === 'production' ? 'none' : true,
secure: process.env.NODE_ENV === 'production',
httpOnly: true,
maxAge: 1000 * 60 * 60 * 24 * 30, // 1 month
// path: "/",
// domain: "*",
// secure: process.env.NODE_ENV === "production",
// maxAge: ms("1d")
},
store: MongoStore.create({
mongoUrl:
'mongodb+srv://kanban-user:[email protected]/kanban-board?retryWrites=true&w=majority',
}),
})
);
createDB()
.then((db) => {
const context = (req, res) => ({
...req,
...res,
models,
db,
});
const server = new ApolloServer({
typeDefs,
resolvers: {
...query,
...mutation,
},
context,
introspection: true, // enables introspection of the schema
playground: true, // enables the actual playground
endpoint: '/graphql',
});
server.applyMiddleware({
app,
cors: {
credentials: true,
origin: [
'https://eeqwu.csb.dev',
'https://eeqwu.codesandbox.io',
'https://csb-eeqwu-gmkjkvyotg.now.sh',
'https://kanban.vercel.app',
'http://localhost:3000',
],
},
});
const opts = {
port: 4000,
};
app.listen(opts, () => {
console.log(`🚀 Server ready at http://localhost:4000`);
});
})
.catch((err) => {
console.error(err);
});