You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
paste/router.js

41 lines
1.0 KiB
JavaScript

const config = require('config');
const router = require('koa-router')();
4 years ago
const conditional = require('koa-conditional-get')();
const etag = require('koa-etag')();
const body = require('koa-body')({
json: false,
multipart: true,
formLimit: config.sizeLimit,
textLimit: config.sizeLimit,
formidable: {
multiples: false,
maxFileSize: require('bytes').parse(config.sizeLimit)
},
onError: (err, ctx) => {
if (err.message.startsWith('maxFileSize')) {
ctx.throw(400, 'Paste Exceeds Maximum Size (' + config.sizeLimit.toUpperCase() + ')');
} else {
ctx.throw(500, err.message);
}
}
});
const pastes = require('./controllers/pastes');
9 years ago
router
4 years ago
.get('/', conditional, etag, async (ctx) => {
ctx.set('Cache-Control', 'public');
4 years ago
await ctx.render('index', {
pretty: config.prettyHtml,
title: config.name,
url: ctx.request.origin,
expires: config.expires,
expiresDefault: config.expiresDefault,
highlights: config.highlights
});
})
.post('/', body, pastes.create)
4 years ago
.get('/:id', conditional, etag, pastes.view);
9 years ago
module.exports = router;