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