Skip to content

Instantly share code, notes, and snippets.

@xoor-io
Created June 11, 2018 19:31
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 xoor-io/72089cfda7c8eee4048601724cdc8e3d to your computer and use it in GitHub Desktop.
Save xoor-io/72089cfda7c8eee4048601724cdc8e3d to your computer and use it in GitHub Desktop.
graphql-server
// 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