fix: resolve route conflict /api/checklisten/{slug}/instances vs /api/checklisten/instances/{id}
Move instance-specific endpoints to /api/checklist-instances/{id} to avoid
Go 1.22+ ServeMux ambiguity panic. Server was crash-looping.
This commit is contained in:
@@ -3,7 +3,7 @@ import { Sidebar } from "./components/Sidebar";
|
||||
import { Footer } from "./components/Footer";
|
||||
|
||||
// Interactive instance page. Loads template + instance JSON, renders
|
||||
// checkboxes, PATCHes /api/checklisten/instances/{id} on every toggle.
|
||||
// checkboxes, PATCHes /api/checklist-instances/{id} on every toggle.
|
||||
// Reset button POSTs to .../reset.
|
||||
export function renderChecklistenInstance(): string {
|
||||
return "<!DOCTYPE html>" + (
|
||||
|
||||
@@ -287,7 +287,7 @@ function initNewInstance() {
|
||||
|
||||
async function deleteInstance(id: string) {
|
||||
try {
|
||||
const resp = await fetch(`/api/checklisten/instances/${encodeURIComponent(id)}`, { method: "DELETE" });
|
||||
const resp = await fetch(`/api/checklist-instances/${encodeURIComponent(id)}`, { method: "DELETE" });
|
||||
if (!resp.ok && resp.status !== 204) {
|
||||
alert(t("checklisten.instances.delete.error"));
|
||||
return;
|
||||
|
||||
@@ -74,7 +74,7 @@ function doneItems(): number {
|
||||
async function loadInstance(): Promise<boolean> {
|
||||
const id = instanceID();
|
||||
if (!id) return false;
|
||||
const resp = await fetch(`/api/checklisten/instances/${encodeURIComponent(id)}`);
|
||||
const resp = await fetch(`/api/checklist-instances/${encodeURIComponent(id)}`);
|
||||
if (!resp.ok) return false;
|
||||
instance = await resp.json();
|
||||
if (instance && typeof instance.state !== "object") instance.state = {};
|
||||
@@ -224,7 +224,7 @@ function updateProgress() {
|
||||
async function patchState(patch: Record<string, boolean>) {
|
||||
if (!instance) return;
|
||||
try {
|
||||
const resp = await fetch(`/api/checklisten/instances/${encodeURIComponent(instance.id)}`, {
|
||||
const resp = await fetch(`/api/checklist-instances/${encodeURIComponent(instance.id)}`, {
|
||||
method: "PATCH",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ state: patch }),
|
||||
@@ -249,7 +249,7 @@ function initReset() {
|
||||
const ok = confirm(t("checklisten.reset.confirm"));
|
||||
if (!ok) return;
|
||||
try {
|
||||
const resp = await fetch(`/api/checklisten/instances/${encodeURIComponent(instance.id)}/reset`, {
|
||||
const resp = await fetch(`/api/checklist-instances/${encodeURIComponent(instance.id)}/reset`, {
|
||||
method: "POST",
|
||||
});
|
||||
if (!resp.ok) {
|
||||
@@ -306,7 +306,7 @@ function initRename() {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
const resp = await fetch(`/api/checklisten/instances/${encodeURIComponent(instance.id)}`, {
|
||||
const resp = await fetch(`/api/checklist-instances/${encodeURIComponent(instance.id)}`, {
|
||||
method: "PATCH",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ name: newName }),
|
||||
|
||||
Reference in New Issue
Block a user