-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.js
59 lines (50 loc) · 1.52 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
const express = require('express');
const app = express();
const morgan = require('morgan');
const mongoose = require('mongoose');
const cors = require('cors');
const bodyParser = require('body-parser');
const cookieParser = require('cookie-parser');
require('dotenv').config();
const stkRoutes = require('./api/routes/index');
var swaggerUi = require('swagger-ui-express'),
swaggerDocument = require('./swagger.json');
const graphqlHttp = require('express-graphql');
const graphqlResolvers = require('./api/graphql/resolvers/index');
const graphqlSchemas = require('./api/graphql/schemas/index');
app.use(morgan('dev'));
app.use(bodyParser.urlencoded({extended:false}));
app.use(bodyParser.json());
app.use(cors());
app.use(cookieParser());
mongoose.connect(process.env.MONGODB_URL,{useNewUrlParser:true},(err)=>{
if(err){
console.log('Error Connection To Database',err.message);
throw new Error(err.message);
}
console.log('MongoDB Connected Successfully');
});
app.use('/api/v1/stkpush/',stkRoutes);
app.use('/api/v1/docs', swaggerUi.serve, swaggerUi.setup(swaggerDocument));
app.use('/graphql',graphqlHttp({
schema: graphqlSchemas,
rootValue: graphqlResolvers,
graphiql:true
}))
app.use('/favicon.ico',(req,res)=>{
res.status(200).send({});
});
app.use(function(req,res,next){
const error = new Error('Route not found');
error.status = 404;
next(error);
});
app.use(function(err,req,res){
res.status(err.status || 500);
res.json({
err:{
message:err.message
}
})
});
module.exports = app;