Created
June 11, 2018 19:31
-
-
Save xoor-io/72089cfda7c8eee4048601724cdc8e3d to your computer and use it in GitHub Desktop.
graphql-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'; | |
const app = express(); | |
function setPort(port = 5000) { | |
app.set('port', parseInt(port, 10)); | |
} | |
function listen() { | |
const port = app.get('port') || 5000; | |
app.listen(port, () => { | |
console.log(`The server is running and listening at http://localhost:${port}`); | |
}); | |
} | |
app.use(cors({ | |
origin: '*', // 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' }); | |
}); | |
export default { | |
getApp: () => app, | |
setPort, | |
listen | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment