WebServer: moved non-static endpoints to /api/

This commit is contained in:
Thomas Kolb 2019-12-14 23:09:37 +01:00
parent 917627c0d0
commit b1f1647260

View file

@ -220,6 +220,11 @@ void WebServer::handleStatic(httpsserver::HTTPRequest *req, httpsserver::HTTPRes
{
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)) {
req->discardRequestBody();
@ -232,31 +237,31 @@ void WebServer::handleStatic(httpsserver::HTTPRequest *req, httpsserver::HTTPRes
void WebServer::serverTask(void *arg)
{
httpsserver::ResourceNode *nodeRoot = new httpsserver::ResourceNode("/", "GET",
WebServer::handleRoot);
httpsserver::ResourceNode *nodeColor = new httpsserver::ResourceNode("/color", "GET",
WebServer::handleColor);
httpsserver::ResourceNode *nodeSetAnim = new httpsserver::ResourceNode("/setanim", "GET",
WebServer::handleSetAnim);
httpsserver::ResourceNode *nodeUpdate = new httpsserver::ResourceNode("/update", "POST",
WebServer::handleUpdate);
httpsserver::ResourceNode *nodeChallenge = new httpsserver::ResourceNode("/challenge", "GET",
WebServer::handleChallenge);
httpsserver::ResourceNode *nodeAuthTest = new httpsserver::ResourceNode("/authtest", "GET",
WebServer::handleAuthTest);
httpsserver::ResourceNode *nodeRoot =
new httpsserver::ResourceNode("/", "GET", WebServer::handleRoot);
httpsserver::ResourceNode *nodeAPIColor =
new httpsserver::ResourceNode("/api/color", "GET", WebServer::handleColor);
httpsserver::ResourceNode *nodeAPISetAnim =
new httpsserver::ResourceNode("/api/setanim", "GET", WebServer::handleSetAnim);
httpsserver::ResourceNode *nodeAPIUpdate =
new httpsserver::ResourceNode("/api/update", "POST", WebServer::handleUpdate);
httpsserver::ResourceNode *nodeAPIChallenge =
new httpsserver::ResourceNode("/api/challenge", "GET", WebServer::handleChallenge);
httpsserver::ResourceNode *nodeAPIAuthTest =
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.
httpsserver::ResourceNode *nodeStatic = new httpsserver::ResourceNode("", "GET",
WebServer::handleStatic);
httpsserver::ResourceNode *nodeStatic =
new httpsserver::ResourceNode("", "GET", WebServer::handleStatic);
WebServer &server = WebServer::instance();
server.m_server->registerNode(nodeRoot);
server.m_server->registerNode(nodeColor);
server.m_server->registerNode(nodeSetAnim);
server.m_server->registerNode(nodeUpdate);
server.m_server->registerNode(nodeChallenge);
server.m_server->registerNode(nodeAuthTest);
server.m_server->registerNode(nodeAPIColor);
server.m_server->registerNode(nodeAPISetAnim);
server.m_server->registerNode(nodeAPIUpdate);
server.m_server->registerNode(nodeAPIChallenge);
server.m_server->registerNode(nodeAPIAuthTest);
server.m_server->setDefaultNode(nodeStatic);
Serial.println("[server] Starting HTTP Server...");