-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathapp.js
36 lines (31 loc) · 847 Bytes
/
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
const express = require('express');
const bodyParser = require('body-parser');
const graphQLHTTP = require('express-graphql');
const mongoose = require('mongoose');
const schema = require('./graphql/schema/index');
const rootValue = require('./graphql/resolvers/index');
const isAuth = require('./middleware/is-auth');
const app = express();
app.use(bodyParser.json());
app.use(isAuth);
app.use(
'/graphql',
graphQLHTTP({
graphiql: true,
schema: schema,
rootValue: rootValue
})
);
mongoose
.connect(
`mongodb+srv://${process.env.MONGO_USER}:${
process.env.MONGO_PASSWORD
}@cluster0-2ajo4.mongodb.net/${process.env.MONGO_DB}?retryWrites=true`,
{ useNewUrlParser: true }
)
.then(() =>
app.listen(3000, () => {
console.log('Server is listening');
})
)
.catch(err => console.log(err));