f0ckv2/src/inc/routes/index.mjs

23 lines
655 B
JavaScript
Raw Normal View History

2019-04-25 18:00:47 +00:00
import router from "../router";
2019-04-25 19:25:38 +00:00
import fs from "fs";
import sql from "../sql";
import handlebars from "handlebars";
2019-04-25 18:00:47 +00:00
2019-04-25 19:25:38 +00:00
import { queries } from "./inc/index";
const template = fs.readFileSync("./views/index.html.tpl", "utf-8");
router.get(/^\/$/, async (req, res) => {
const db = await sql;
res.writeHead(200, { 'Content-Type': 'text/html' });
db.query(queries.items)
.then(items => {
const tpl = handlebars.compile(template);
res.end(tpl({ items: items, debug: JSON.stringify(req.url, null, 2) }));
2019-04-25 19:25:38 +00:00
}).catch(err => res.end(JSON.stringify( err ), 'utf-8'));
/*const tpl = handlebars.compile(template);
res.end(tpl());*/
2019-04-25 18:00:47 +00:00
});