Skip to content

Commit

Permalink
feat(server): rename create server file
Browse files Browse the repository at this point in the history
  • Loading branch information
calebmer committed Apr 23, 2016
1 parent 7d26e8e commit 6379744
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
9 changes: 4 additions & 5 deletions src/createExpressServer.js → src/createServer.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import path from 'path'
import http from 'http'
import Express from 'express'
import onFinished from 'on-finished'
import logger from 'morgan'
import favicon from 'serve-favicon'
import pg from 'pg'
import { formatError } from 'graphql'
import graphql from 'express-graphql'
import graphqlHTTP from 'express-graphql'

/**
* Creates an HTTP server with the provided configuration.
Expand All @@ -23,7 +24,7 @@ const createServer = async ({ graphqlSchema, pgConfig, route, development }) =>
server.use(logger(development ? 'dev' : 'common'))
server.use(favicon(path.join(__dirname, '../assets/favicon.ico')))

server.use(route || '/', graphql(async req => {
server.use(route || '/', graphqlHTTP(async req => {
// Acquire a new client for every request.
const client = await pg.connectAsync(pgConfig)
// Make sure we release our client back to the pool once the response has
Expand All @@ -38,9 +39,7 @@ const createServer = async ({ graphqlSchema, pgConfig, route, development }) =>
}
}))

// Lol, we actually return an express server, but we might not in the
// future ;)
return server
return http.createServer(server)
}

export default createServer
Expand Down
4 changes: 2 additions & 2 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { readFileSync } from 'fs'
import { Command } from 'commander'
import { parse as parseConnectionString } from 'pg-connection-string'
import createGraphqlSchema from './createGraphqlSchema.js'
import createExpressServer from './createExpressServer.js'
import createServer from './createServer.js'

const manifest = readFileSync(path.resolve(__dirname, '../package.json'))

Expand Down Expand Up @@ -51,7 +51,7 @@ const main = async () => {
const graphqlSchema = await createGraphqlSchema(pgConfig, schemaName)

// Create the GraphQL HTTP server.
const server = await createExpressServer({
const server = await createServer({
graphqlSchema,
pgConfig,
route,
Expand Down

0 comments on commit 6379744

Please sign in to comment.