-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
43 lines (38 loc) · 1.19 KB
/
server.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import express from 'express';
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;
// GraphQL server
const graphQLServer = express();
graphQLServer.use('/', graphqlHTTP({
schema: schema,
pretty: true,
graphiql: true,
}));
graphQLServer.listen(GRAPHQL_PORT, () => console.log(`GraphQL server on localhost:${GRAPHQL_PORT}`));
// Relay
const compiler = webpack({
entry:['whatwg-fetch', path.resolve(__dirname, 'src', 'App.js')],
module: {
loaders: [
{
exclude: /node_modules/,
loader: 'babel-loader',
test: /\.js$/,
},
],
},
output: {filename: 'App.js', path: '/'}
});
const app = new WebPackDevServer(compiler, {
contentBase: '/public/',
proxy: {'/graphql': `http://localhost:${GRAPHQL_PORT}`},
publicPath: '/src/',
stats: {colors: true},
});
app.use('/', express.static(path.resolve(__dirname, 'public')));
app.listen(APP_PORT, () => console.log(`App is now running on localhost:${APP_PORT}`));