Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@chris001177
Created June 22, 2019 19:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chris001177/4a972a09bba66ef4ded0be65c43460c4 to your computer and use it in GitHub Desktop.
Save chris001177/4a972a09bba66ef4ded0be65c43460c4 to your computer and use it in GitHub Desktop.
const express = require('express')
const bodyParser = require('body-parser')
const { graphqlExpress } = require('apollo-server-express')
const schema = require('./schema')
const jwt = require('express-jwt')
const app = express()
// bodyparser
app.use(bodyParser.json())
// authentication middleware
const authMiddleware = jwt({
secret: 'somesuperdupersecret'
})
app.use(authMiddleware)
app.use('/api', graphqlExpress(req => ({
schema,
context: {
user: req.user
}
})))
app.listen(3000, () => {
console.log('Server is up on 3000')
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment