Code tidy.
This commit is contained in:
parent
b94f6c328b
commit
1aa945c986
@ -3,36 +3,30 @@ import cors from 'kcors'
|
||||
import compress from 'koa-compress'
|
||||
import KoaRouter from 'koa-router'
|
||||
import koaBody from 'koa-bodyparser'
|
||||
import { makeExecutableSchema } from 'graphql-tools'
|
||||
import { graphqlKoa } from 'graphql-server-koa'
|
||||
import { apolloUploadKoa } from 'apollo-upload-server'
|
||||
import types from './schema.mjs'
|
||||
import { graphqlKoa } from 'graphql-server-koa'
|
||||
import { makeExecutableSchema } from 'graphql-tools'
|
||||
import typeDefs from './schema.mjs'
|
||||
import resolvers from './resolvers.mjs'
|
||||
|
||||
const server = new Koa()
|
||||
const app = new Koa()
|
||||
const router = new KoaRouter()
|
||||
|
||||
server
|
||||
// Enable Cross-Origin Resource Sharing (CORS)
|
||||
.use(cors())
|
||||
// Enable gzip
|
||||
.use(compress())
|
||||
|
||||
// GraphQL API
|
||||
router.post(
|
||||
'/graphql',
|
||||
koaBody(),
|
||||
apolloUploadKoa(),
|
||||
graphqlKoa({
|
||||
schema: makeExecutableSchema({ typeDefs: [types], resolvers })
|
||||
})
|
||||
graphqlKoa({ schema: makeExecutableSchema({ typeDefs, resolvers }) })
|
||||
)
|
||||
|
||||
server.use(router.routes()).use(router.allowedMethods())
|
||||
|
||||
server.listen(process.env.PORT, error => {
|
||||
if (error) throw new Error(error)
|
||||
app
|
||||
.use(cors())
|
||||
.use(compress())
|
||||
.use(router.routes())
|
||||
.use(router.allowedMethods())
|
||||
|
||||
app.listen(process.env.PORT, error => {
|
||||
if (error) throw error
|
||||
// eslint-disable-next-line no-console
|
||||
console.info(
|
||||
`Serving http://localhost:${process.env.PORT} for ${process.env.NODE_ENV}.`
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user