-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathrouter.js
More file actions
29 lines (27 loc) · 809 Bytes
/
router.js
File metadata and controls
29 lines (27 loc) · 809 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
const config = require('config');
const router = require('koa-router')();
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');
router
.get('/', conditional, etag, pastes.index)
.post('/', body, pastes.create)
.get('/:id', conditional, etag, pastes.view);
module.exports = router;