44b7d804bc3b84782e1a2809ecff53aa991ce95c
1 let router
= require("express").Router();
2 const createError
= require('http-errors');
3 const sqlite3
= require('sqlite3');
4 const DbPath
= __dirname
.replace("/routes", "/db/vchess.sqlite");
5 const db
= new sqlite3
.Database(DbPath
);
6 const selectLanguage
= require(__dirname
.replace("/routes", "/utils/language.js"));
8 router
.get("/:variant([a-zA-Z0-9]+)", (req
,res
,next
) => {
9 const vname
= req
.params
["variant"];
10 db
.serialize(function() {
11 db
.all("SELECT * FROM Variants WHERE name='" + vname
+ "'", (err
,variant
) => {
14 if (!variant
|| variant
.length
==0)
15 return next(createError(404));
16 res
.render('variant', {
17 title: vname
+ ' Variant',
19 lang: selectLanguage(req
, res
),
25 // Load a rules page (AJAX)
26 router
.get("/rules/:variant([a-zA-Z0-9]+)", (req
,res
) => {
28 return res
.json({errmsg: "Unauthorized access"});
29 const lang
= selectLanguage(req
, res
);
30 res
.render("rules/" + req
.params
["variant"] + "/" + lang
);
33 module
.exports
= router
;