Created
June 22, 2019 19:37
-
-
Save chris001177/4a972a09bba66ef4ded0be65c43460c4 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 { 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