-
Notifications
You must be signed in to change notification settings - Fork 35
/
router.js
29 lines (24 loc) · 937 Bytes
/
router.js
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 router = require('koa-router')();
const config = require('config');
const name = require('sillyname');
const email = require('./controllers/email');
const sse = require('./controllers/sse');
router.get('/', async (ctx) => {
ctx.set('Cache-Control', 'public');
await ctx.render('index', {
pretty: config.app.prettyHtml,
title: config.app.title,
defaultAddress: name.randomAdjective().toLowerCase() + '-' + name.randomNoun() + '@' + config.mail.domains[Math.floor(Math.random() * config.mail.domains.length)],
domains: config.mail.domains
});
});
router.param('email', email.validateEmail);
router.param('id', email.validateId);
router.get('/:email.json', email.get);
router.get('/:email.feed', sse.subscribe);
router.post('/:email', email.test);
router.get('/:id.html', email.html);
router.get('/:id.txt', email.text);
router.get('/:id.raw', email.raw);
router.delete('/:id', email.delete);
module.exports = router;