Permalink
Cannot retrieve contributors at this time
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?
crm/index.js
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
38 lines (29 sloc)
950 Bytes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Koa from 'koa' | |
import serve from 'koa-static' | |
import views from 'koa-views' | |
import session from 'koa-session' | |
import bodyParser from 'koa-body' | |
import router from './routes/routes.js' | |
const app = new Koa() | |
app.keys = ['darkSecret'] | |
const defaultPort = 8080 | |
const port = process.env.PORT || defaultPort | |
async function getHandlebarData(ctx, next) { | |
console.log(`${ctx.method} ${ctx.path}`) | |
ctx.hbs = { | |
authorised: ctx.session.authorised, | |
user: ctx.session.user, | |
userid: ctx.session.userid, | |
host: `https://${ctx.host}` | |
} | |
for(const key in ctx.query) ctx.hbs[key] = ctx.query[key] | |
await next() | |
} | |
app.use(serve('public')) | |
app.use(bodyParser({multipart: true})) | |
app.use(session(app)) | |
app.use(views('views', { extension: 'handlebars' }, {map: { handlebars: 'handlebars' }})) | |
app.use(getHandlebarData) | |
app.use(router.routes()) | |
app.use(router.allowedMethods()) | |
app.listen(port, async() => console.log(`listening on port ${port}`)) |