diff --git a/bin/app.js b/bin/app.js index 79e53be..7e2d78c 100644 --- a/bin/app.js +++ b/bin/app.js @@ -3,29 +3,36 @@ import FastifyStatic from "@fastify/static"; import path from "path"; import { ToDo } from "../lib/models.js"; import fs from "fs"; -import _ from "lodash"; +import template from "lodash/template.js"; const fastify = Fastify({ logger: true }); -fastify.get("/todo", async (request, reply) => { - const list = await ToDo.all({}); +fastify.get("/todo", async (req, rep) => { + try { + const todo_list = await ToDo.all({}); - return list; -}); + // this is for exporing the problem of getting good error messages from templates + const tmpl_src = fs.readFileSync("templates/todo.html"); + const tmpl = template(tmpl_src, {sourceURL: "templates/todo.html"}); -fastify.get("/todo.html", async (req, rep) => { - const list = await ToDo.all({}); + console.log("FUNCTION-----\n", tmpl.toString()); - const tmpl_src = fs.readFileSync("templates/todo.html"); - const tmpl = _.template(tmpl_src, ); + const result = tmpl({todo_list}); - const result = tmpl({message: "Hello!"}); + rep.code(200) + .type("text/html") + .send(result); + } catch(error) { + console.error(error); + console.error(error.stack); + console.error(error.source); + } +}); + +fastify.get("/todo.html", async (req, rep) => { - rep.code(200) - .type("text/html") - .send(result); }); fastify.register(FastifyStatic, { diff --git a/templates/todo.html b/templates/todo.html index 7c8a6bb..cc3a6d8 100644 --- a/templates/todo.html +++ b/templates/todo.html @@ -3,27 +3,24 @@ + Bandolier2 -blockquote { - --_accent-1: var(--lime-5); - --_accent-2: var(--lime-4); - --_bg: var(--surface-2); - --_ink: var(--text-1); + + - color: var(--_ink); - border-color: var(--_accent-2); - background-color: var(--_bg); - justify-self: flex-start; -} - - -

<%= message %>

+

<%= your_todos %>

-

This is a template!

+
    + <% for(let todo of todo_list) { %> +
  1. <%= todo.task %>
  2. + <% } %> +