d-a-v / ESPWebDAV

macOS, linux, windows: Natively sharing files - port 80 is shared
Other
41 stars 9 forks source link

Redirect "/" to "/.www/index.html" #14

Open idolpx opened 3 years ago

idolpx commented 3 years ago

I want to use "/" as root for WebDAV but I would like to rewrite the URL for "/" to "/.www/index.html" so my web configuration app will be accessible by default.

#if WEBSERVER_HAS_HOOK
WebServer::HookFunction hookWebDAVForWebserver(const String& davRootDir, ESPWebDAVCore& dav)
{
    return [&dav, davRootDir](const String & method, const String & url, WiFiClient * client, WebServer::ContentTypeFunction contentType)
    {
        if (url == "/")
        {
            DBG_PRINT("WE ARE AT ROOT!");
            url = "/.www/index.html";
        }

        if (url.indexOf(".www") != 0)
        {
            DBG_PRINT("CLIENT_REQUEST_CAN_CONTINUE, %s is not seen in %s", davRootDir.c_str(), url.c_str());
            return WebServer::CLIENT_REQUEST_CAN_CONTINUE;
        }

This does not work. Is there a way to do this?

idolpx commented 3 years ago

Actually it would be cool if it could detect a webbrowser and just bypass webdav and serve up web pages as usual. That's kinda what I'm trying to do here.

I love having the webdav access to root but when accessing via a web browser I just want it to serve up html.

d-a-v commented 3 years ago

@idolpx The API and the example are updated with what's needed about your feature request.

idolpx commented 3 years ago

Thanks! Trying to get this to work now.

d-a-v commented 2 years ago

Have you had a chance to try ?