Created
June 12, 2018 14:29
-
-
Save xoor-io/e3604c48b65fe9023f59fbbd50965da3 to your computer and use it in GitHub Desktop.
graphql-final-server
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
// HTTP SERVER | |
import express from 'express'; | |
import cors from 'cors'; | |
// GraphQL - Apollo | |
import apollo from './graphql'; | |
// Config | |
import config from './config'; | |
const app = express(); | |
function setPort(port = 5000) { | |
app.set('port', parseInt(port, 10)); | |
} | |
function listen() { | |
const port = app.get('port') || config.port; | |
app.listen(port, () => { | |
console.log(`The server is running and listening at http://localhost:${port}`); | |
}); | |
} | |
app.use(cors({ | |
origin: config.corsDomain, // Be sure to switch to your production domain | |
optionsSuccessStatus: 200 | |
})); | |
// Endpoint to check if the API is running | |
app.get('/api/status', (req, res) => { | |
res.send({ status: 'ok' }); | |
}); | |
// Append apollo to our API | |
apollo(app); | |
export default { | |
getApp: () => app, | |
setPort, | |
listen | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment