server eslinted

This commit is contained in:
tmshv committed 2017-01-22 07:33:53 +03:00
1 parent 17de1d0fac
commit 37d85879d3
1 file changed
+43 -43
+43 -43
View File
@@ -1,67 +1,67 @@
import path from 'path'; import path from 'path'
import {Server} from 'http'; import {Server} from 'http'
import Koa from 'koa'; import Koa from 'koa'
import serve from 'koa-static'; import serve from 'koa-static'
import logger from 'koa-logger'; import logger from 'koa-logger'
import convert from 'koa-convert'; import convert from 'koa-convert'
import conditional from 'koa-conditional-get'; import conditional from 'koa-conditional-get'
import etag from 'koa-etag'; import etag from 'koa-etag'
import prerender from 'koa-prerender'; import prerender from 'koa-prerender'
import helmet from 'koa-helmet'; import helmet from 'koa-helmet'
import mount from 'koa-mount'; import mount from 'koa-mount'
import bodyParser from 'koa-bodyparser'; import bodyParser from 'koa-bodyparser'
import apiV1 from 'hudozka-api-v1'; import apiV1 from 'hudozka-api-v1'
import config, {redirectionTable} from './config'; import config, {redirectionTable} from './config'
import {routes, queryObject} from './routes'; import {routes, queryObject} from './routes'
import {redirect} from './routes/redirect'; import {redirect} from './routes/redirect'
import {services as serviceKeys, authChecker} from './core/service'; import {services as serviceKeys, authChecker} from './core/service'
import handlebars from 'handlebars'; import handlebars from 'handlebars'
const dirPublic = path.join(__dirname, '../public'); const dirPublic = path.join(__dirname, '../public')
const dirTemplates = path.join(__dirname, 'templates'); const dirTemplates = path.join(__dirname, 'templates')
handlebars.registerHelper('raw-helper', options => options.fn()); handlebars.registerHelper('raw-helper', options => options.fn())
export default function (store) { export default function (store) {
const $ = convert; const $ = convert
const app = new Koa(); const app = new Koa()
app.proxy = true; app.proxy = true
app.use(bodyParser({ app.use(bodyParser({
extendTypes: { extendTypes: {
json: 'application/ejson' json: 'application/ejson'
} }
})); }))
app.use(logger()); app.use(logger())
app.use(apis(store)); app.use(apis(store))
app.use($(conditional())); app.use($(conditional()))
app.use($(etag())); app.use($(etag()))
app.use(prerenderRmFragment()); app.use(prerenderRmFragment())
app.use($(prerender(config.prerender))); app.use($(prerender(config.prerender)))
app.use(serve(dirPublic)); app.use(serve(dirPublic))
app.use(serve(dirTemplates)); app.use(serve(dirTemplates))
app.use($(redirect(redirectionTable))); app.use($(redirect(redirectionTable)))
app.use($(helmet())); app.use($(helmet()))
app.use(queryObject()); app.use(queryObject())
app.use(routes(store)); app.use(routes(store))
return Server(app.callback()); return Server(app.callback())
} }
function apis(store) { function apis(store) {
let checkAuth = authChecker(serviceKeys); let checkAuth = authChecker(serviceKeys)
return mount('/api/v1', apiV1(checkAuth, store)); return mount('/api/v1', apiV1(checkAuth, store))
} }
function prerenderRmFragment() { function prerenderRmFragment() {
return async(ctx, next) => { return async(ctx, next) => {
await next(); await next()
try { try {
let xp = ctx.response.header['x-prerender'] === 'true'; let xp = ctx.response.header['x-prerender'] === 'true'
if (xp) ctx.body = ctx.body.replace('<meta name="fragment" content="!">', ''); if (xp) ctx.body = ctx.body.replace('<meta name="fragment" content="!">', '')
} catch (e) { } catch (e) {
} }
} }