nfp_sites/old/server.mjs

40 lines
1 KiB
JavaScript
Raw Normal View History

2021-01-04 17:47:59 +00:00
import Koa from 'koa-lite'
2019-02-19 11:34:52 +00:00
import bodyParser from 'koa-bodyparser'
import cors from '@koa/cors'
2021-02-05 11:50:01 +00:00
import config from './config.mjs'
import router from './router.mjs'
import Jwt from './jwt.mjs'
import log from './log.mjs'
import { serve } from './serve.mjs'
import { mask } from './middlewares/mask.mjs'
import { errorHandler } from './error/middleware.mjs'
import { accessChecks } from './access/middleware.mjs'
import ParserMiddleware from './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