import { ToDo } from "../lib/models.js"; import nunjucks from "nunjucks"; export class Todo { async get(req, rep) { if(req.headers.accept === "application/json") { const todo_list = await ToDo.all({}); rep.code(200).send(todo_list); } else { const result = nunjucks.render("todo_alpine.html", {name: "Zed"}); rep.code(200).type("text/html").send(result); } } async post(req, rep) { if(req.query.todo_id !== undefined) { await ToDo.delete({id: req.query.todo_id}); } else { await ToDo.insert({task: req.body.task}); } await this.get(req, rep); } } // you use the export default to set the route URL? // I mean, it works not sure if I like it though export default { todo_alpine: Todo, };