-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
41 lines (34 loc) · 1.04 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
const express = require('express');
const bodyParser = require('body-parser');
const graphqlHttp = require('express-graphql');
const mongoose = require('mongoose');
const graphiQlSchema = require('./graphql-core/schema/index');
const graphiQlResolvers = require('./graphql-core/resolvers/index');
const isAuth = require('./middleware/is-auth');
const app = express();
const events = [];
app.use(bodyParser.json());
app.get('/', (req, res, next) => {
res.send('Hello world!');
})
app.use(isAuth)
app.use('/graphql', graphqlHttp({
schema: graphiQlSchema,
rootValue: graphiQlResolvers,
graphiql: true,
}));
const mongoUser = process.env.MONGO_USER;
const mongoPassword = process.env.MONGO_PWD;
const mongoDB = process.env.MONGO_DB;
mongoose.connect(
`mongodb+srv://${mongoUser}:${
mongoPassword
}@myfirstcluster-mlbxs.mongodb.net/${mongoDB}?retryWrites=true&w=majority`
).then(() => {
app.listen(3000);
})
.catch(
(err) => {
console.error('An error occurred at connecting mongoDB', err);
}
)