Last active
October 3, 2017 11:13
-
-
Save Bensigo/3d679ab6784341b6af9fafddfd51810d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const express = require('express') | |
const bodyParser = require('body-parser') | |
const mongoose = require('mongoose') | |
const cors = require('cors') | |
const {graphiqlExpress, graphqlExpress} = require('apollo-server-express') | |
const morgan = require('morgan') | |
// require app modules | |
const config = require('./config/config') | |
const schema = require('./graphql') | |
// making instance of app | |
const app = express() | |
// setting up middlewares | |
app.use(cors()) // TODO: add origin for the fontend | |
app.use(morgan('dev')) | |
// setup graphiql and graphql server | |
app.use('/graphiql', graphiqlExpress({ | |
endpointURL: '/graphql' | |
})) | |
app.use('/graphql', bodyParser.json(), graphqlExpress(req => ({ | |
schema | |
}))) | |
// connect to DB | |
mongoose.connect(config.DBURI, () => { | |
console.log('connected to DB successfully') | |
}) | |
// start app server | |
app.listen(config.PORT, () => { | |
console.log('starting up graphql server') | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment