nfp_sites/server.mjs

40 lines
1.1 KiB
JavaScript
Raw Normal View History

2019-02-19 11:34:52 +00:00
import Koa from 'koa'
import bodyParser from 'koa-bodyparser'
import cors from '@koa/cors'
2019-09-14 19:03:38 +00:00
import config from './api/config.mjs'
import router from './api/router.mjs'
import Jwt from './api/jwt.mjs'
import log from './api/log.mjs'
import { serve } from './api/serve.mjs'
import { mask } from './api/middlewares/mask.mjs'
import { errorHandler } from './api/error/middleware.mjs'
import { accessChecks } from './api/access/middleware.mjs'
import ParserMiddleware from './api/parser/middleware.mjs'
2019-02-19 11:34:52 +00:00
const app = new Koa()
const parser = new ParserMiddleware()
2019-09-13 13:33:10 +00:00
app.use(log.logMiddleware())
2019-02-19 11:34:52 +00:00
app.use(errorHandler())
2019-09-13 13:33:10 +00:00
app.use(mask())
2019-02-19 11:34:52 +00:00
app.use(bodyParser())
app.use(parser.contextParser())
app.use(accessChecks())
app.use(parser.generateLinks())
app.use(Jwt.jwtMiddleware())
app.use(cors({
exposeHeaders: ['link', 'pagination_total'],
credentials: true,
}))
app.use(router.routes())
app.use(router.allowedMethods())
app.use(serve('./public', '/public'))
const server = app.listen(
config.get('server:port'),
() => log.info(`Server running on port ${config.get('server:port')}`)
)
export default server