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