|
|
|
@ -3,7 +3,7 @@ import FastifyStatic from "@fastify/static"; |
|
|
|
|
import path from "path"; |
|
|
|
|
import { ToDo } from "../lib/models.js"; |
|
|
|
|
import fs from "fs"; |
|
|
|
|
import template from "lodash/template.js"; |
|
|
|
|
import nunjucks from "nunjucks"; |
|
|
|
|
|
|
|
|
|
const fastify = Fastify({ |
|
|
|
|
logger: true |
|
|
|
@ -14,12 +14,8 @@ fastify.get("/todo", async (req, rep) => { |
|
|
|
|
const todo_list = await ToDo.all({}); |
|
|
|
|
|
|
|
|
|
// 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"}); |
|
|
|
|
|
|
|
|
|
console.log("FUNCTION-----\n", tmpl.toString()); |
|
|
|
|
|
|
|
|
|
const result = tmpl({todo_list}); |
|
|
|
|
const result = nunjucks.render("templates/todo.html", |
|
|
|
|
{todo_list, your_todos: "Your Todos"}); |
|
|
|
|
|
|
|
|
|
rep.code(200) |
|
|
|
|
.type("text/html") |
|
|
|
@ -31,10 +27,6 @@ fastify.get("/todo", async (req, rep) => { |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
fastify.get("/todo.html", async (req, rep) => { |
|
|
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
fastify.register(FastifyStatic, { |
|
|
|
|
root: path.join(path.resolve("."), 'static'), |
|
|
|
|
prefix: '/', // optional: default '/'
|
|
|
|
|