-
Notifications
You must be signed in to change notification settings - Fork 6
/
routes.js
58 lines (45 loc) · 1.74 KB
/
routes.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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
var express = require('express');
var router = express.Router();
//const util = require('util')
async function doStuff(req, res, next, controllerFile, pugFile) {
try {
const file = res.app.root + '/controllers/' + controllerFile + '.js';
const controller = require(file);
let result = await controller(req, res);
if (result === null || result === undefined) {
res.sendStatus(404);
} else if (typeof result === "object") {
if (result.json !== undefined) res.json(result.json);
else res.render(pugFile, result);
} else if (typeof result == "string") {
res.redirect(result);
}
} catch (e) {
console.log(e);
}
}
function addGet(route, controllerFile, pugFile) {
if (pugFile == undefined) pugFile = controllerFile;
router.get(route, (req, res, next) => { doStuff(req, res, next, controllerFile, pugFile); });
}
addGet('/', 'home');
addGet('/corp/', 'corps');
addGet('/alli/', 'allis');
addGet('/character/:id', 'character');
addGet('/corporation/:id', 'corporation');
addGet('/alliance/:id', 'alliance');
addGet('/pilot/:id', 'character');
addGet('/corp/:id', 'corporation');
addGet('/alli/:id', 'alliance');
addGet('/pug/list/:id/:which/:page', 'puglist');
addGet('/api/:type/:id', 'api');
// Redirects for old evewho
router.get('/pilot/:id', (req, res, next) => { res.send('/character/' + req.params.id); });
router.get('/corp/:id', (req, res, next) => { res.send('/corporation/' + req.params.id); });
router.get('/alli/:id', (req, res, next) => { res.send('/alliance/' + req.params.id); });
// Search!
router.get('/autocomplete/', async function(req, res, next) {
const controller = require(res.app.root + '/controllers/autocomplete.js');
await controller(req, res);
});
module.exports = router;