Skip to content
This repository has been archived by the owner on Feb 8, 2024. It is now read-only.

Commit

Permalink
Add requestHandler (fixes #119)
Browse files Browse the repository at this point in the history
  • Loading branch information
maakbaas committed Nov 6, 2021
1 parent 6a10866 commit 7d033c2
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
21 changes: 21 additions & 0 deletions docs/web-server.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,27 @@ The web server has only one public method. Call this method in your setup functi

## Class Members

#### requestHandler
```c++
ArRequestHandlerFunction requestHandler = serveProgmem;
```

Use this to override the requestHandler before calling `GUI.begin()`:

```c++
GUI.requestHandler = alternativeRequest; //override request handler
GUI.begin();
```
With another request handler, such as:

```c++
void alternativeRequest(AsyncWebServerRequest *request)
{
request->send(200, "text/plain", "Hello World!");
}
```
This allows you to add your own logic into the webserver.
#### server
```c++
Expand Down
2 changes: 1 addition & 1 deletion src/webServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ void webServer::begin()

server.serveStatic("/download", LittleFS, "/");

server.onNotFound(serveProgmem);
server.onNotFound(requestHandler);

//handle uploads
server.on(PSTR("/upload"), HTTP_POST, [](AsyncWebServerRequest *request) {}, handleFileUpload);
Expand Down
1 change: 1 addition & 0 deletions src/webServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class webServer
public:
AsyncWebServer server = AsyncWebServer(80);
AsyncWebSocket ws = AsyncWebSocket("/ws");
ArRequestHandlerFunction requestHandler = serveProgmem;
void begin();
};

Expand Down

0 comments on commit 7d033c2

Please sign in to comment.