-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
40 lines (30 loc) · 1.01 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 expressGraphQL = require("express-graphql").graphqlHTTP;
const PORT = process.env.PORT || 3009
const dbConfig = require('./config/dbconfig.js');
const mongoose = require('mongoose');
mongoose.Promise = global.Promise;
const app = express()
app.use(bodyParser.urlencoded({ extended: true }))
app.use(bodyParser.json())
mongoose.connect(dbConfig.url, {
useNewUrlParser: true
}).then(() => {
console.log("Successfully connected to the database");
}).catch(err => {
console.log('Could not connect to the database. Exiting now...', err);
process.exit();
});
app.use('/api/v1', require('./routes/index'));
app.use('/api/v2/graphql', expressGraphQL({
schema: require('./graphql/schema'),
graphiql: true
}));
app.use('/docs', express.static('view/doc.html'))
app.get('/' , (req,res)=>{
res.send({"message":"Goto /docs for documentation"})
})
app.listen(PORT , ()=>{
console.log(`App Running on Port ${PORT}`)
})