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