-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
68 lines (64 loc) · 1.52 KB
/
app.js
File metadata and controls
68 lines (64 loc) · 1.52 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
60
61
62
63
64
65
66
67
68
import { graphqlHTTP } from 'express-graphql';
import express, { json } from 'express';
import MongoStore from 'connect-mongo';
import session from 'express-session';
import compression from 'compression';
import xss from 'xss-clean';
import morgan from 'morgan';
import helmet from 'helmet';
import cors from 'cors';
import path from 'path';
import Router from './routes';
import graphqlSchema from './graphql/schema';
import * as graphqlResolvers from './graphql/resolvers';
const app = express();
app
.use(morgan('combined'))
.enable('trust proxy')
.use(
helmet.contentSecurityPolicy({
directives: {
...helmet.contentSecurityPolicy.getDefaultDirectives(),
'img-src': ["'self'", 'data:', 'https:'],
},
}),
)
.use(cors())
.options('*', cors())
.use(xss())
.use(express.static(path.join(__dirname, 'build')))
.use(
session({
name: 'Gitline-sid',
secret: process.env.AUTH_SECRET,
saveUninitialized: false,
resave: false,
store: MongoStore.create({
mongoUrl: process.env.MONGODB_CONNECT_STORE,
mongoOptions: {
useNewUrlParser: true,
useUnifiedTopology: true,
},
}),
cookie: {
maxAge: 8 * 3600 * 1000,
sameSite: 'strict',
secure: process.env.NODE_ENV === 'production',
},
}),
)
.use(compression())
.use(json())
.use(Router)
.use(
'/graphql',
graphqlHTTP({
schema: graphqlSchema,
rootValue: graphqlResolvers,
graphiql: true,
}),
)
.get('*', (_req, res) =>
res.sendFile(path.join(__dirname, 'build', 'index.html')),
);
export default app;