-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
45 lines (40 loc) · 1.23 KB
/
app.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
const express = require('express')
const bodyParser = require('body-parser')
const graphqlHttp = require('express-graphql')
const mongoose = require('mongoose')
const compression = require('compression')
const app = express();
const path = require('path')
const graphQlSchema = require('./graphql/schema/index')
const graphQlResolvers = require('./graphql/resolvers/index')
const isAuth = require('./middleware/is-auth')
const cors = require('./middleware/cors')
app
.use(cors)
.use(compression())
.use(bodyParser.urlencoded({ extended: true }))
.use(express.static('public'))
.use(express.json())
.use(isAuth)
.use(
'/graphql',
graphqlHttp({
schema: graphQlSchema,
rootValue: graphQlResolvers,
graphiql: true
})
);
const PORT = process.env.PORT || 3001
app.get('*', (req, res) => {
res.sendFile(path.resolve(__dirname, '/../public/index.html'));
})
mongoose
.connect(`mongodb+srv://${process.env.MONGO_USER}:${process.env.MONGO_PASSWORD}@cluster0-xn2pr.mongodb.net/${process.env.MONGO_DB}?retryWrites=true&w=majority`, {
useNewUrlParser: true,
useUnifiedTopology: true
})
.then(() => {
app.listen(PORT, () => console.log(`server started on port ${PORT}`));
}).catch(err => {
console.log(err)
})