Skip to content

Instantly share code, notes, and snippets.

@amenuor
Created November 11, 2015 21:21
Show Gist options
  • Save amenuor/e7d1508a0bde196758b8 to your computer and use it in GitHub Desktop.
Save amenuor/e7d1508a0bde196758b8 to your computer and use it in GitHub Desktop.
CORS on GraphQL Server from relay-starter-kit
import express from 'express';
import cors from 'cors';
import graphQLHTTP from 'express-graphql';
import path from 'path';
import webpack from 'webpack';
import WebpackDevServer from 'webpack-dev-server';
import {Schema} from './data/schema';
const APP_PORT = 3000;
const GRAPHQL_PORT = 8080;
// Expose a GraphQL endpoint
var graphQLServer = express();
graphQLServer.use(cors());
graphQLServer.use('/', graphQLHTTP({
graphiql: true,
pretty: true,
schema: Schema,
}));
graphQLServer.listen(GRAPHQL_PORT, () => console.log(
`GraphQL Server (CORS enabled) is now running on http://localhost:${GRAPHQL_PORT}`
));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment