Save current state (unmerged, broken, not working...)
[vchess.git] / routes / variant.js
CommitLineData
298c42e6
BA
1let router = require("express").Router();
2const createError = require('http-errors');
8d7e2786
BA
3const VariantModel = require("../models/Variant");
4const selectLanguage = require("../utils/language.js");
5const access = require("../utils/access");
298c42e6
BA
6
7router.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 23router.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
28module.exports = router;