Skip to content
Permalink
5e990b4b0c
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
33 lines (23 sloc) 788 Bytes
import Koa from 'koa'
import serve from 'koa-static'
import views from 'koa-views'
import session from 'koa-session'
import { apiRouter } from './routes/routes.js'
const app = new Koa()
app.keys = ['darkSecret']
const defaultPort = 8080
const port = process.env.PORT || defaultPort
app.use(serve('public'))
app.use(session(app))
app.use(views('views', { extension: 'handlebars' }, {map: { handlebars: 'handlebars' }}))
app.use( async(ctx, next) => {
console.log(`${ctx.method} ${ctx.path}`)
ctx.hbs = {
authorised: ctx.session.authorised,
host: `https://${ctx.host}`
}
for(const key in ctx.query) ctx.hbs[key] = ctx.query[key]
await next()
})
app.use(apiRouter.routes(), apiRouter.allowedMethods())
app.listen(port, async() => console.log(`listening on port ${port}`))