Commit | Line | Data |
---|---|---|
298c42e6 BA |
1 | let router = require("express").Router(); |
2 | const createError = require('http-errors'); | |
8d7e2786 BA |
3 | const VariantModel = require("../models/Variant"); |
4 | const selectLanguage = require("../utils/language.js"); | |
5 | const access = require("../utils/access"); | |
298c42e6 BA |
6 | |
7 | router.get("/:variant([a-zA-Z0-9]+)", (req,res,next) => { | |
8 | const vname = req.params["variant"]; | |
8d7e2786 BA |
9 | VariantModel.getByName(vname, (err,variant) => { |
10 | if (!!err) | |
11 | return next(err); | |
12 | if (!variant) | |
13 | return next(createError(404)); | |
14 | res.render('variant', { | |
15 | title: vname + ' Variant', | |
16 | variant: variant, //the variant ID might also be useful | |
17 | lang: selectLanguage(req, res), | |
298c42e6 BA |
18 | }); |
19 | }); | |
20 | }); | |
21 | ||
22 | // Load a rules page (AJAX) | |
8d7e2786 | 23 | router.get("/rules/:vname([a-zA-Z0-9]+)", access.ajax, (req,res) => { |
298c42e6 | 24 | const lang = selectLanguage(req, res); |
8d7e2786 | 25 | res.render("rules/" + req.params["vname"] + "/" + lang); |
298c42e6 BA |
26 | }); |
27 | ||
28 | module.exports = router; |