app.use(serve('public', { maxage: config.get('NODE_ENV') === 'development' ? 0 : 7.2e6, // 2 hours in ms gzip: false })); app.use(nunjucks('views', { ext: '.html', noCache: config.get('NODE_ENV') === 'development', throwOnUndefined: true, filters: { json: function(str) { return JSON.stringify(str, null, 2); }, uriEncode: function(str) { return encodeURIComponent(str); }, formatSatoshis: belt.formatSatoshis, formatNumber: belt.formatNumber, timeAgo: timeAgo }, globals: { lottoAddress: config.get('LOTTERY_ADDRESS'), dustThreshold: config.get('DUST_THRESHOLD') } })); app.use(bodyParser()); app.use(function*(next) { try { yield* next; } catch(ex) {
app.use(mw.ensureReferer()); app.use(require('koa-helmet')()); app.use(require('koa-compress')()); app.use(require('koa-better-static')('public')); // Don't show logger in test mode if (config.NODE_ENV !== 'test') { app.use(require('koa-logger')()); } app.use(require('koa-body')({ multipart: true })); app.use(mw.methodOverride()); // Must come after body parser app.use(mw.removeTrailingSlash()); app.use(mw.wrapCurrUser()); app.use(mw.wrapFlash('flash')); app.use(bouncer.middleware()); app.use(mw.handleBouncerValidationError()); // Must come after bouncer.middleware() app.use(nunjucksRender('views', nunjucksOptions)); // Provide a convience function for protecting our routes behind // our authorization rules. If authorization check fails, 404 response. // // Usage: // // router.get('/topics/:id', function*() { // const topic = yield db.getTopicById(this.params.id); // this.assertAuthorized(this.currUser, 'READ_TOPIC', topic); // ... // }); app.use(function*(next) { this.assertAuthorized = (user, action, target) => { const isAuthorized = cancan.can(user, action, target); const uname = (user && user.uname) || '<Guest>';