async/await
This commit is contained in:
@ -9,14 +9,16 @@ const template = fs.readFileSync("./views/index.hbs", "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());*/
|
||||
try {
|
||||
const rows = await db.query(queries.items);
|
||||
const tpl = handlebars.compile(template);
|
||||
res
|
||||
.writeHead(200, { 'Content-Type': 'text/html' })
|
||||
.end(tpl({ items: rows, debug: JSON.stringify(req.url, null, 2) }));
|
||||
} catch(err) {
|
||||
res
|
||||
.writeHead(500)
|
||||
.end(JSON.stringify(err), 'utf-8');
|
||||
}
|
||||
});
|
||||
|
Reference in New Issue
Block a user