-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
41 lines (31 loc) · 1.15 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
const express = require('express');
const morgan = require('morgan');
const bodyParser = require('body-parser');
const compression = require('compression');
const graphqlHTTP = require('express-graphql');
const graphqlSchema = require('./graphqlSchema');
const mongoConn = require('./mongoConnection')();
let app = express();
// Configure morgan to log your requests, with a standard date & time format
morgan.token('time', (req, res) => new Date().toISOString());
app.use(morgan('[:time] :remote-addr :method :url :status :res[content-length] :response-time ms'));
// app.use(compression());
// Setup bodyParsing middleware
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
// Avoid frequent (spam) favicon request by sending no content status
app.use('/favicon.ico', function(req, res, next) {
res.status(204);
next();
});
// Mount the APIs specific to version
app.use('/api/v1', require('./api/v1'));
app.use('/', graphqlHTTP({
schema: graphqlSchema,
graphiql: ((process.NODE_ENV !== 'production') ? true : false),
/*rootValue: {},
context: {},
pretty: false,
formatError: undefined*/
}));
module.exports = app;