WebServer: moved non-static endpoints to /api/
This commit is contained in:
parent
917627c0d0
commit
b1f1647260
|
@ -220,6 +220,11 @@ void WebServer::handleStatic(httpsserver::HTTPRequest *req, httpsserver::HTTPRes
|
||||||
{
|
{
|
||||||
std::string filename = "/htdocs" + req->getRequestString();
|
std::string filename = "/htdocs" + req->getRequestString();
|
||||||
|
|
||||||
|
if(*(filename.end()-1) == '/') {
|
||||||
|
// looks like a directory name, so append 'index.html'
|
||||||
|
filename.append("index.html");
|
||||||
|
}
|
||||||
|
|
||||||
if(!serveFile(filename.c_str(), res)) {
|
if(!serveFile(filename.c_str(), res)) {
|
||||||
req->discardRequestBody();
|
req->discardRequestBody();
|
||||||
|
|
||||||
|
@ -232,31 +237,31 @@ void WebServer::handleStatic(httpsserver::HTTPRequest *req, httpsserver::HTTPRes
|
||||||
|
|
||||||
void WebServer::serverTask(void *arg)
|
void WebServer::serverTask(void *arg)
|
||||||
{
|
{
|
||||||
httpsserver::ResourceNode *nodeRoot = new httpsserver::ResourceNode("/", "GET",
|
httpsserver::ResourceNode *nodeRoot =
|
||||||
WebServer::handleRoot);
|
new httpsserver::ResourceNode("/", "GET", WebServer::handleRoot);
|
||||||
httpsserver::ResourceNode *nodeColor = new httpsserver::ResourceNode("/color", "GET",
|
httpsserver::ResourceNode *nodeAPIColor =
|
||||||
WebServer::handleColor);
|
new httpsserver::ResourceNode("/api/color", "GET", WebServer::handleColor);
|
||||||
httpsserver::ResourceNode *nodeSetAnim = new httpsserver::ResourceNode("/setanim", "GET",
|
httpsserver::ResourceNode *nodeAPISetAnim =
|
||||||
WebServer::handleSetAnim);
|
new httpsserver::ResourceNode("/api/setanim", "GET", WebServer::handleSetAnim);
|
||||||
httpsserver::ResourceNode *nodeUpdate = new httpsserver::ResourceNode("/update", "POST",
|
httpsserver::ResourceNode *nodeAPIUpdate =
|
||||||
WebServer::handleUpdate);
|
new httpsserver::ResourceNode("/api/update", "POST", WebServer::handleUpdate);
|
||||||
httpsserver::ResourceNode *nodeChallenge = new httpsserver::ResourceNode("/challenge", "GET",
|
httpsserver::ResourceNode *nodeAPIChallenge =
|
||||||
WebServer::handleChallenge);
|
new httpsserver::ResourceNode("/api/challenge", "GET", WebServer::handleChallenge);
|
||||||
httpsserver::ResourceNode *nodeAuthTest = new httpsserver::ResourceNode("/authtest", "GET",
|
httpsserver::ResourceNode *nodeAPIAuthTest =
|
||||||
WebServer::handleAuthTest);
|
new httpsserver::ResourceNode("/api/authtest", "GET", WebServer::handleAuthTest);
|
||||||
|
|
||||||
// handle all remaining requests by trying to serve static files. If no file is found, 404 is generated.
|
// handle all remaining requests by trying to serve static files. If no file is found, 404 is generated.
|
||||||
httpsserver::ResourceNode *nodeStatic = new httpsserver::ResourceNode("", "GET",
|
httpsserver::ResourceNode *nodeStatic =
|
||||||
WebServer::handleStatic);
|
new httpsserver::ResourceNode("", "GET", WebServer::handleStatic);
|
||||||
|
|
||||||
WebServer &server = WebServer::instance();
|
WebServer &server = WebServer::instance();
|
||||||
|
|
||||||
server.m_server->registerNode(nodeRoot);
|
server.m_server->registerNode(nodeRoot);
|
||||||
server.m_server->registerNode(nodeColor);
|
server.m_server->registerNode(nodeAPIColor);
|
||||||
server.m_server->registerNode(nodeSetAnim);
|
server.m_server->registerNode(nodeAPISetAnim);
|
||||||
server.m_server->registerNode(nodeUpdate);
|
server.m_server->registerNode(nodeAPIUpdate);
|
||||||
server.m_server->registerNode(nodeChallenge);
|
server.m_server->registerNode(nodeAPIChallenge);
|
||||||
server.m_server->registerNode(nodeAuthTest);
|
server.m_server->registerNode(nodeAPIAuthTest);
|
||||||
server.m_server->setDefaultNode(nodeStatic);
|
server.m_server->setDefaultNode(nodeStatic);
|
||||||
|
|
||||||
Serial.println("[server] Starting HTTP Server...");
|
Serial.println("[server] Starting HTTP Server...");
|
||||||
|
|
Loading…
Reference in a new issue