Skip to content

Instantly share code, notes, and snippets.

@guzmonne
Created March 27, 2017 00:56
Show Gist options
  • Save guzmonne/49122305b6f7ef7e8941ca21991bdf42 to your computer and use it in GitHub Desktop.
Save guzmonne/49122305b6f7ef7e8941ca21991bdf42 to your computer and use it in GitHub Desktop.
Express server with GraphQL endpoint
const express = require('express')
const bodyParser = require('body-parser')
const cors = require('cors')
const {graphqlExpress, graphiqlExpress} = require('graphql-server-express')
const schema = require('../graphql/schema.js')
const PORT = 3000
const app = express()
app.use('*', cors())
// bodyParser is needed just for POST
app.use('/graphql', bodyParser.json(), log, graphqlExpress({
schema,
}))
app.use('/graphiql', graphiqlExpress({
endpointURL: '/graphql',
}))
app.get('/on', (req, res) => (res.status(200).json({ok: true})))
app.listen(PORT)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment