From 7896616c16570100f6fbc8c07065e2e5b6248df5 Mon Sep 17 00:00:00 2001 From: Jonatan Nilsson Date: Tue, 7 Apr 2020 11:00:18 +0000 Subject: [PATCH] More cleanup --- api/middlewares.mjs | 40 ---------------------------------------- api/server.mjs | 28 ---------------------------- 2 files changed, 68 deletions(-) delete mode 100644 api/middlewares.mjs diff --git a/api/middlewares.mjs b/api/middlewares.mjs deleted file mode 100644 index a0e8711..0000000 --- a/api/middlewares.mjs +++ /dev/null @@ -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, - }) - } - } -} diff --git a/api/server.mjs b/api/server.mjs index 8b06a8b..a6f086b 100644 --- a/api/server.mjs +++ b/api/server.mjs @@ -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)