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";
|
|
|
|
|
2019-04-26 04:24:57 +00:00
|
|
|
const template = fs.readFileSync("./views/index.hbs", "utf-8");
|
2019-04-25 19:25:38 +00:00
|
|
|
|
|
|
|
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);
|
2019-04-26 04:19:20 +00:00
|
|
|
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
|
|
|
});
|