-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
50 lines (42 loc) · 1.2 KB
/
Copy pathapp.js
File metadata and controls
50 lines (42 loc) · 1.2 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
const express = require('express');
const bodyParser = require('body-parser');
const graphqlHTTP = require('express-graphql');
const mongoose = require('mongoose');
const expressValidator = require('express-validator');
const cors = require('cors');
const graphQlSchema = require('./graphql/schema');
// const isAuth = require('./middleware/is-auth');
require('dotenv').config();
const app = express();
mongoose.Promise = global.Promise;
// TODO: cane add permission handle for open routes
// app.use(isAuth)
mongoose.Promise = global.Promise;
mongoose.set('debug', true);
app.use(cors());
app.use(bodyParser.json());
app.use(expressValidator());
app.use('/graphql', graphqlHTTP({
schema: graphQlSchema,
context: () => {
return {id: 1};
},
graphiql: true,
}));
mongoose
.connect(
`${process.env.MONGO_USER}`,
{useNewUrlParser: true, useUnifiedTopology: true}
)
.then(() => {
console.log('Successfully connect to the DB');
app.listen(process.env.PORT, (res, err) => {
if (err) {
console.log(`something went wrong: ${err.message}`);
}
console.log(`Connect to the Server on port: ${process.env.PORT}`);
});
})
.catch((err) => {
console.log(err);
});