diff --git a/examples/device-dashboard/net.c b/examples/device-dashboard/net.c index 03b85bc3..f93c3ceb 100644 --- a/examples/device-dashboard/net.c +++ b/examples/device-dashboard/net.c @@ -180,7 +180,7 @@ static size_t print_events(void (*out)(char, void *), void *ptr, va_list *ap) { return len; } -static void handle_events_set(struct mg_connection *c, struct mg_http_message *hm) { +static void handle_events_get(struct mg_connection *c, struct mg_http_message *hm) { int pageno = mg_json_get_long(hm->body, "$.page", 1); mg_http_reply(c, 200, s_json_header, "{%m:[%M], %m:%d}", MG_ESC("arr"), print_events, pageno, MG_ESC("totalCount"), MAX_EVENTS_NO); @@ -237,8 +237,8 @@ static void fn(struct mg_connection *c, int ev, void *ev_data, void *fn_data) { handle_debug(c, hm); } else if (mg_http_match_uri(hm, "/api/stats/get")) { handle_stats_get(c); - } else if (mg_http_match_uri(hm, "/api/events/set")) { - handle_events_set(c, hm); + } else if (mg_http_match_uri(hm, "/api/events/get")) { + handle_events_get(c, hm); } else if (mg_http_match_uri(hm, "/api/settings/get")) { handle_settings_get(c); } else if (mg_http_match_uri(hm, "/api/settings/set")) { diff --git a/examples/device-dashboard/web_root/main.js b/examples/device-dashboard/web_root/main.js index 34213343..87ddb6e8 100644 --- a/examples/device-dashboard/web_root/main.js +++ b/examples/device-dashboard/web_root/main.js @@ -1,3 +1,5 @@ +// NOTE: API calls must start with 'api/' in order to serve the app at any URI + 'use strict'; import { h, render, useState, useEffect, useRef, html, Router } from './bundle.js'; import { Icons, Login, Setting, Button, Stat, tipColors, Colored, Notification, Pagination } from './components.js'; @@ -55,7 +57,7 @@ function Events({}) { const [page, setPage] = useState(1); const refresh = () => - fetch('/api/events/set', { + fetch('api/events/get', { method: 'POST', body: JSON.stringify({page: page}), }).then(r => r.json()) .then(r => setEvents(r)); @@ -109,30 +111,7 @@ return html` /> -/>` - - /*return html` -