diff --git a/controllers/todo_alpine.js b/controllers/todo_alpine.js index 80355f0..dea9fc4 100644 --- a/controllers/todo_alpine.js +++ b/controllers/todo_alpine.js @@ -1,21 +1,15 @@ import { ToDo } from "../lib/models.js"; import nunjucks from "nunjucks"; -// this can go away when I learn how to detect the request type -export class TodoIndex { - async get(req, rep) { - const todo_list = await ToDo.all({}); - - const result = nunjucks.render("todo_alpine.html", {name: "Zed"}); - - rep.code(200).type("text/html").send(result); - } -} - export class Todo { async get(req, rep) { - const todo_list = await ToDo.all({}); - rep.code(200).send(todo_list); + 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) { @@ -33,5 +27,4 @@ export class Todo { // I mean, it works not sure if I like it though export default { todo_alpine: Todo, - todo_index: TodoIndex }; diff --git a/templates/todo_alpine.html b/templates/todo_alpine.html index ba0241e..4362306 100644 --- a/templates/todo_alpine.html +++ b/templates/todo_alpine.html @@ -5,8 +5,29 @@ @@ -14,7 +35,7 @@
+ x-init="todos = await list_todo()">