Move index route to controller

master
Joe Biellik 6 years ago
parent 95b4d3003a
commit ecd0647250

@ -4,6 +4,16 @@ const isBinaryFile = require('isbinaryfile').isBinaryFile;
const Paste = require('../models/paste'); const Paste = require('../models/paste');
module.exports = { module.exports = {
async index(ctx) {
await ctx.render('index', {
pretty: config.prettyHtml,
title: config.name,
url: ctx.request.origin,
expires: config.expires,
highlights: config.highlights
});
},
async view(ctx) { async view(ctx) {
try { try {
const paste = await Paste.findById(ctx.params.id).exec(); const paste = await Paste.findById(ctx.params.id).exec();

@ -22,18 +22,7 @@ const body = require('koa-body')({
const pastes = require('./controllers/pastes'); const pastes = require('./controllers/pastes');
router router
.get('/', conditional, etag, async (ctx) => { .get('/', conditional, etag, pastes.index)
ctx.set('Cache-Control', 'public');
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) .post('/', body, pastes.create)
.get('/:id', conditional, etag, pastes.view); .get('/:id', conditional, etag, pastes.view);

Loading…
Cancel
Save