chore: loads of lgtm maintainability fixes

This commit is contained in:
Katie Thornhill 2019-11-19 23:22:37 -05:00
parent 0b918d9ffa
commit eb6dce5277
No known key found for this signature in database
GPG key ID: F76EDC6541A99644
13 changed files with 44 additions and 98 deletions

View file

@ -39,7 +39,6 @@ module.exports = (R, $) => {
})
R.get('/api/server/:id/slug', async ctx => {
const { userId } = ctx.session
const { id } = ctx.params
const srv = $.discord.client.guilds.get(id)

View file

@ -53,10 +53,6 @@ async function start() {
const pub = path.resolve(path.join(__dirname, 'public'))
log.info('public path', pub)
const staticFiles = require('koa-static')
// app.use(staticFiles(pub, { defer: true, gzip: true, br: true }))
const send = require('koa-send')
app.use(async (ctx, next) => {
if (ctx.path.startsWith('/api')) {
log.info('api breakout')
@ -85,40 +81,15 @@ async function start() {
try {
ctx.body = fs.readFileSync(path.join(pub, 'index.html'), { encoding: 'utf-8' })
} catch (e) {
ctx.body = e.stack || e.trace
ctx.body = "A problem occured."
ctx.status = 500
console.error(e)
}
log.info('index sent')
ctx.status = 200
return next()
}
// try {
// await next()
// } catch (e) {
// send(ctx, 'index.html', { root: pub })
// }
})
// const sendOpts = {root: pub, index: 'index.html'}
// // const sendOpts = {}
// app.use(async (ctx, next) => {
// if (ctx.path.startsWith('/api')) {
// return await next()
// }
// try {
// log.info('pass 1', ctx.path, __dirname+'/public'+ctx.path)
// await send(ctx, __dirname+'/public'+ctx.path, sendOpts)
// } catch (error) {
// try {
// log.info('pass 2 /', ctx.path, __dirname+'/public/index.html')
// await send(ctx, __dirname+'/public/index.html', sendOpts)
// } catch (error) {
// log.info('exit to next', ctx.path)
// await next()
// }
// }
// })
}
// Request logger
@ -129,20 +100,21 @@ async function start() {
} catch (e) {
log.error(e)
ctx.status = ctx.status || 500
if (DEVEL) {
ctx.body = ctx.body || e.stack
} else {
ctx.body = {
err: 'something terrible happened.',
}
console.error(e)
}
ctx.body = {
err: 'something terrible happened.',
}
}
let timeElapsed = new Date() - timeStart
log.request(
`${ctx.status} ${ctx.method} ${ctx.url} - ${ctx.ip} - took ${timeElapsed}ms`
)
// return null
})
const session = require('koa-session')
@ -164,7 +136,6 @@ async function start() {
await M.mountRoutes()
// SPA server
log.info(`starting HTTP server on ${process.env.APP_PORT || 6769}`)
server.listen(process.env.APP_PORT || 6769)
}

View file

@ -1,7 +1,6 @@
const log = new (require('../logger'))('models/index')
const glob = require('glob')
const path = require('path')
const util = require('../util/model-methods')
module.exports = sql => {
const models = {}