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 => { R.get('/api/server/:id/slug', async ctx => {
const { userId } = ctx.session
const { id } = ctx.params const { id } = ctx.params
const srv = $.discord.client.guilds.get(id) const srv = $.discord.client.guilds.get(id)

View file

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

View file

@ -1,10 +1,9 @@
import React, { Component } from 'react' import React, { Component } from 'react'
import { Link } from 'react-router-dom'
import TypingDemo from '../demos/typing'
import RoleypolyDemo from '../demos/roleypoly'
import * as Actions from '../../actions' import * as Actions from '../../actions'
import './styles.sass'
import discordLogo from '../../pages/images/discord-logo.svg' import discordLogo from '../../pages/images/discord-logo.svg'
import RoleypolyDemo from '../demos/roleypoly'
import TypingDemo from '../demos/typing'
import './styles.sass'
export default class AddServer extends Component { export default class AddServer extends Component {
polling = null polling = null

View file

@ -1,9 +1,6 @@
import React, { Component } from 'react' import React, { Component } from 'react'
import { Redirect } from 'react-router-dom'
import superagent from 'superagent'
import { connect } from 'react-redux' import { connect } from 'react-redux'
import { push } from 'react-router-redux' import superagent from 'superagent'
import { fetchServers } from '../../actions'
@connect() @connect()
class OauthCallback extends Component { class OauthCallback extends Component {

View file

@ -1,17 +1,14 @@
import React, { Component } from 'react'
import { Set } from 'immutable' import { Set } from 'immutable'
import { connect } from 'react-redux' import React, { Component } from 'react'
import { DropTarget } from 'react-dnd'
import { Link, Prompt, Redirect } from 'react-router-dom'
import { Scrollbars } from 'react-custom-scrollbars' import { Scrollbars } from 'react-custom-scrollbars'
import * as Actions from './actions' import { DropTarget } from 'react-dnd'
import * as PickerActions from '../role-picker/actions' import { connect } from 'react-redux'
import { Link, Prompt, Redirect } from 'react-router-dom'
import * as UIActions from '../../actions/ui' import * as UIActions from '../../actions/ui'
import './RoleEditor.sass'
import Category from './Category'
import CategoryEditor from './CategoryEditor'
import Role from '../role/draggable' import Role from '../role/draggable'
import * as Actions from './actions'
import Category from './Category'
import './RoleEditor.sass'
const mapState = ({ rolePicker, roleEditor, servers }, ownProps) => ({ const mapState = ({ rolePicker, roleEditor, servers }, ownProps) => ({
rp: rolePicker, rp: rolePicker,

View file

@ -1,15 +1,11 @@
import React, { Component, Fragment } from 'react' import React, { Component } from 'react'
import { connect } from 'react-redux' import { connect } from 'react-redux'
import { Prompt } from 'react-router-dom' import { Link, Prompt } from 'react-router-dom'
import superagent from 'superagent'
import * as Actions from './actions'
import * as UIActions from '../../actions/ui' import * as UIActions from '../../actions/ui'
import { msgToReal } from '../../utils' import { msgToReal } from '../../utils'
import './RolePicker.sass' import * as Actions from './actions'
import Category from './Category' import Category from './Category'
import { Scrollbars } from 'react-custom-scrollbars' import './RolePicker.sass'
import { Link } from 'react-router-dom'
const mapState = ({ rolePicker, servers }, ownProps) => { const mapState = ({ rolePicker, servers }, ownProps) => {
return { return {

View file

@ -1,9 +1,7 @@
import React, { Component } from 'react' import React, { Component } from 'react'
import { connect } from 'react-redux'
import ImmutablePropTypes from 'react-immutable-proptypes' import ImmutablePropTypes from 'react-immutable-proptypes'
import { NavLink } from 'react-router-dom' import { NavLink } from 'react-router-dom'
import './ServerCard.sass' import './ServerCard.sass'
import { withRouter } from 'react-router'
class ServerCard extends Component { class ServerCard extends Component {
static propTypes = { static propTypes = {

View file

@ -1,15 +1,14 @@
import React, { Component } from 'react' import React, { Component } from 'react'
import { Route, Switch } from 'react-router-dom'
import { Scrollbars } from 'react-custom-scrollbars' import { Scrollbars } from 'react-custom-scrollbars'
import { connect } from 'react-redux' import { connect } from 'react-redux'
import { withRouter, Redirect } from 'react-router' import { Redirect } from 'react-router'
import './index.sass' import { Route, Switch } from 'react-router-dom'
import Navigation from './Navigation'
import RolePicker from '../role-picker'
import RoleEditor from '../role-editor'
import AddServer from '../add-server'
import Error404 from '../../pages/Error404' import Error404 from '../../pages/Error404'
import AddServer from '../add-server'
import RoleEditor from '../role-editor'
import RolePicker from '../role-picker'
import './index.sass'
import Navigation from './Navigation'
// import mockData from './mockData' // import mockData from './mockData'

View file

@ -1,12 +1,9 @@
import React, { Component, Fragment } from 'react' import React from 'react'
import { Link } from 'react-router-dom' import { Link } from 'react-router-dom'
import Scrollbars from 'react-custom-scrollbars'
import Typist from 'react-typist'
import moment from 'moment'
import './landing.sass'
import discordLogo from './images/discord-logo.svg'
import RoleypolyDemo from '../components/demos/roleypoly' import RoleypolyDemo from '../components/demos/roleypoly'
import TypingDemo from '../components/demos/typing' import TypingDemo from '../components/demos/typing'
import discordLogo from './images/discord-logo.svg'
import './landing.sass'
const Landing = ({ root = false }) => ( const Landing = ({ root = false }) => (
<div className="landing uk-width-1-1 uk-text-center"> <div className="landing uk-width-1-1 uk-text-center">

View file

@ -1,4 +1,4 @@
import { Map, OrderedMap, fromJS } from 'immutable' import { Map, OrderedMap } from 'immutable'
const initialState = Map({ const initialState = Map({
viewMap: OrderedMap({}), viewMap: OrderedMap({}),

View file

@ -1,16 +1,13 @@
import React, { Component, Fragment } from 'react' import React, { Component } from 'react'
import { Route, Switch, Redirect } from 'react-router-dom'
import { connect } from 'react-redux' import { connect } from 'react-redux'
import { withRouter } from 'react-router' import { withRouter } from 'react-router'
import { Redirect, Route, Switch } from 'react-router-dom'
import Servers from '../components/servers' import OauthBotFlow from '../components/oauth-bot-flow'
import OauthCallback from '../components/oauth-callback' import OauthCallback from '../components/oauth-callback'
import OauthFlow from '../components/oauth-flow' import OauthFlow from '../components/oauth-flow'
import OauthBotFlow from '../components/oauth-bot-flow' import Servers from '../components/servers'
import Pages, { Landing, Error404 } from '../pages'
import ServerLanding from '../components/servers/ServerLanding' import ServerLanding from '../components/servers/ServerLanding'
import Pages, { Error404, Landing } from '../pages'
const aaa = props => <div>{JSON.stringify(props)}</div>
export default export default
@withRouter @withRouter

View file

@ -1,10 +1,8 @@
import { createStore, applyMiddleware, compose } from 'redux'
import thunk from 'redux-thunk'
import { createLogger } from 'redux-logger'
// import api from '../middleware/api'
import rootReducer from '../reducers'
import DevTools from '../components/dev-tools'
import { routerMiddleware } from 'react-router-redux' import { routerMiddleware } from 'react-router-redux'
import { applyMiddleware, compose, createStore } from 'redux'
import { createLogger } from 'redux-logger'
import thunk from 'redux-thunk'
import rootReducer from '../reducers'
const configureStore = (preloadedState, history) => { const configureStore = (preloadedState, history) => {
const store = createStore( const store = createStore(
@ -12,7 +10,6 @@ const configureStore = (preloadedState, history) => {
preloadedState, preloadedState,
compose( compose(
applyMiddleware(thunk, routerMiddleware(history), createLogger()) applyMiddleware(thunk, routerMiddleware(history), createLogger())
// DevTools.instrument()
) )
) )