import router from "../router"; import fs from "fs"; import sql from "../sql"; import handlebars from "handlebars"; 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) })); }).catch(err => res.end(JSON.stringify( err ), 'utf-8')); /*const tpl = handlebars.compile(template); res.end(tpl());*/ });