Skip to content

Instantly share code, notes, and snippets.

@Industrial
Last active May 27, 2017 00:58
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 Industrial/c6a60084701440cf34876bbfc1f6ecca to your computer and use it in GitHub Desktop.
Save Industrial/c6a60084701440cf34876bbfc1f6ecca to your computer and use it in GitHub Desktop.
proxy_1 | 2017-05-26T11:24:27.715129487Z 172.20.0.1 - - [26/May/2017:11:24:27 +0000] "GET /_next/on-demand-entries-ping?page=/ HTTP/1.1" 200 27 "http://localhost:3000/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36"
app_1 | 2017-05-26T11:24:33.726024587Z <-- GET /_next/on-demand-entries-ping?page=/
app_1 | 2017-05-26T11:24:33.727593387Z
app_1 | 2017-05-26T11:24:33.727633887Z AssertionError: headers have already been sent
app_1 | 2017-05-26T11:24:33.727644987Z at Object.set status [as status] (/service/node_modules/koa/lib/response.js:85:5)
app_1 | 2017-05-26T11:24:33.727675387Z at Object.status (/service/node_modules/delegates/index.js:92:31)
app_1 | 2017-05-26T11:24:33.727689887Z at Object.error (/service/node_modules/koa-errorhandler/index.js:76:21)
app_1 | 2017-05-26T11:24:33.727698187Z at error.throw (<anonymous>)
app_1 | 2017-05-26T11:24:33.727705487Z at onRejected (/service/node_modules/co/index.js:81:24)
app_1 | 2017-05-26T11:24:33.727712887Z
app_1 | 2017-05-26T11:24:33.727908987Z xxx GET /_next/on-demand-entries-ping?page=/ 500 6ms -
const zlib = require('zlib')
const Koa = require('koa')
const Router = require('koa-router')
const koaBodyparser = require('koa-bodyparser')
const koaCompress = require('koa-compress')
const koaConvert = require('koa-convert')
const koaErrorHandler = require('koa-errorhandler')
const koaHelmet = require('koa-helmet')
const koaLogger = require('koa-logger')
const koaPassport = require('koa-passport')
const koaPing = require('koa-ping')
const koaRedis = require('koa-redis')
const koaResponseTime = require('koa-response-time')
const koaSession = require('koa-generic-session')
const koaStatic = require('koa-static')
const log = require('loglevel')
const next = require('next')
const {
NODE_ENV,
REDIS_HOST,
REDIS_PORT,
APP_HOST,
APP_PORT,
APP_KEYS,
} = process.env
if (NODE_ENV === 'develop') {
log.setLevel('debug')
}
const nextApp = next({
dev: process.env.NODE_ENV !== 'production',
})
const handleRequest = nextApp.getRequestHandler()
nextApp
.prepare()
.then(() => {
const app = new Koa()
app.keys = [APP_KEYS.split(',')]
// Hook to convert old Koa.js middleware
const oldUse = app.use
app.use = x => oldUse.call(app, koaConvert(x))
app
.use(koaPing())
.use(koaLogger())
.use(koaErrorHandler())
.use(koaBodyparser())
.use(koaSession({
rolling: true,
store: koaRedis({
host: REDIS_HOST,
port: REDIS_PORT,
}),
}))
.use(koaCompress({
filter: contentType => /text/i.test(contentType),
threshold: 2048,
flush: zlib.Z_SYNC_FLUSH,
}))
.use(koaHelmet())
.use(koaResponseTime())
const router = new Router()
router.get('*', (ctx) => {
handleRequest(ctx.req, ctx.res)
ctx.respond = false
})
app
.use(async (ctx, next) => {
ctx.res.statusCode = 200
await next()
})
.use(router.routes())
app.listen(APP_PORT, APP_HOST, (error) => {
if (error) {
throw error
}
log.info(`> Ready on http://${APP_HOST}:${APP_PORT}`)
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment