Created
March 27, 2017 00:56
-
-
Save guzmonne/49122305b6f7ef7e8941ca21991bdf42 to your computer and use it in GitHub Desktop.
Express server with GraphQL endpoint
This file contains hidden or 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 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