More cleanup

This commit is contained in:
Jonatan Nilsson 2020-04-07 11:00:18 +00:00
parent 4215c07d9c
commit 7896616c16
2 changed files with 0 additions and 68 deletions

View file

@ -1,40 +0,0 @@
export function bunyanLogger(logger) {
return async (ctx, next) => {
ctx.log = logger.child({
})
const d1 = new Date().getTime()
await next()
const d2 = new Date().getTime()
let level = 'info'
if (ctx.status >= 400) {
level = 'warn'
}
if (ctx.status >= 500) {
level = 'error'
}
ctx.log[level]({
duration: (d2 - d1),
status: ctx.res.statusCode,
}, `<-- ${ctx.request.method} ${ctx.request.url}`)
}
}
export function errorHandler() {
return async (ctx, next) => {
try {
await next()
} catch(err) {
ctx.log.error(err, 'Unknown error occured')
ctx.status = 500
ctx.render('error', {
error: err,
})
}
}
}

View file

@ -1,6 +1,3 @@
// import Koa from 'koa'
// import serve from 'koa-better-serve'
// import socket from 'koa-socket'
import socket from 'socket.io-serveronly'
import http from 'http'
import nStatic from 'node-static'
@ -10,7 +7,6 @@ import lowdb from './db.mjs'
import config from './config.mjs'
import log from './log.mjs'
import onConnection from './routerio.mjs'
import { bunyanLogger, errorHandler } from './middlewares.mjs'
log.info('Server: Opening database db.json')
@ -70,30 +66,6 @@ lowdb().then(function(db) {
}
log.info(`Server is listening on ${config.get('server:port')}`)
})
/*
const app = new Koa()
const io = new socket()
io.attach(app)
io.on('connection', onConnection.bind(this, io, db))
casparcg.initialise(log, db, io)
app.use(bunyanLogger(log))
app.use(errorHandler())
app.use(async (ctx, next) => {
if (ctx.url === '/') {
return ctx.redirect('/index.html')
}
await next()
})
app.use(serve('./public', ''))
app.listen(config.get('server:port'), err => {
if (err) return log.fatal(err)
log.info(`Server is listening on ${config.get('server:port')}`)
})*/
}, function(e) {
log.fatal(e, 'Critical error loading database')
process.exit(1)