diff --git a/code/espurna/api.ino b/code/espurna/api.ino index 37a0ca9f..ce2a7ac6 100644 --- a/code/espurna/api.ino +++ b/code/espurna/api.ino @@ -128,8 +128,21 @@ void _onRPC(AsyncWebServerRequest *request) { bool _apiRequestCallback(AsyncWebServerRequest *request) { - // Not API request String url = request->url(); + + // Main API entry point + if (url.equals("/api") || url.equals("/apis")) { + _onAPIs(request); + return true; + } + + // Main RPC entry point + if (url.equals("/rpc")) { + _onRPC(request); + return true; + } + + // Not API request if (!url.startsWith("/api/")) return false; for (unsigned char i=0; i < _apis.size(); i++) { @@ -198,8 +211,6 @@ void apiRegister(const char * key, api_get_callback_f getFn, api_put_callback_f } void apiSetup() { - webServer()->on("/apis", HTTP_GET, _onAPIs); - webServer()->on("/rpc", HTTP_GET, _onRPC); wsOnSendRegister(_apiWebSocketOnSend); wsOnReceiveRegister(_apiWebSocketOnReceive); webRequestRegister(_apiRequestCallback); diff --git a/code/espurna/web.ino b/code/espurna/web.ino index da3bb7a8..9cdad9ba 100644 --- a/code/espurna/web.ino +++ b/code/espurna/web.ino @@ -93,7 +93,9 @@ void _onGetConfig(AsyncWebServerRequest *request) { response->printf("{\n\"app\": \"%s\"", APP_NAME); response->printf(",\n\"version\": \"%s\"", APP_VERSION); response->printf(",\n\"backup\": \"1\""); - response->printf(",\n\"timestamp\": \"%s\"", ntpDateTime().c_str()); + #if NTP_SUPPORT + response->printf(",\n\"timestamp\": \"%s\"", ntpDateTime().c_str()); + #endif // Write the keys line by line (not sorted) unsigned long count = settingsKeyCount(); @@ -392,6 +394,8 @@ void webSetup() { #if WEB_EMBEDDED _server->on("/index.html", HTTP_GET, _onHome); #endif + + // Other entry points _server->on("/reset", HTTP_GET, _onReset); _server->on("/config", HTTP_GET, _onGetConfig); _server->on("/config", HTTP_POST | HTTP_PUT, _onPostConfig, _onPostConfigData); @@ -418,6 +422,7 @@ void webSetup() { #else _server->begin(); #endif + DEBUG_MSG_P(PSTR("[WEBSERVER] Webserver running on port %u\n"), port); }