Fix '3 knights' bug + tiny advance on problems tab
[vchess.git] / routes / all.js
1 var express = require('express');
2 var router = express.Router();
3 var createError = require('http-errors');
4
5 const Variants = require("../variants");
6
7 // Home
8 router.get('/', function(req, res, next) {
9 res.render('index', {
10 title: 'club',
11 variantArray: Variants, //JSON.stringify(Variants)
12 });
13 });
14
15 // Variant
16 router.get("/:vname([a-zA-Z0-9]+)", (req,res,next) => {
17 const vname = req.params["vname"];
18 if (!Variants.some(v => { return (v.name == vname); }))
19 return next(createError(404));
20 res.render('variant', {
21 title: vname + ' Variant',
22 variant: vname,
23 });
24 });
25
26 // Load a rules page (AJAX)
27 router.get("/rules/:variant([a-zA-Z0-9]+)", (req,res) => {
28 res.render("rules/" + req.params["variant"]);
29 });
30
31 module.exports = router;