Skip to content

Server mode does not serve index.html by default when accessing IP:PORT #673

@triuk

Description

@triuk

When running WebUI in server mode, it behaves like a web server. However, opening the root URL (IP:PORT) in a browser does not load the custom UI page. Instead, users must manually enter IP:PORT/index.html.

Expected behavior:
Navigating to IP:PORT should automatically serve index.html.

Actual behavior:
Opening IP:PORT results in a Not Found response, so the user has to access IP:PORT/index.html explicitly.

Suggested fix:
Default the server root to index.html.
In C, this is currently handled by:

const char* url = webui_start_server(myWindow, "/full/root/path");

I am doing cpp, so one workaround was overriding the start behavior manually, for example:

static std::string start_server(webui::window &win, const std::string &file)
{
    // Store start page
    detail::g_start_page = file;

    // Install VFS middleware
    win.set_file_handler(detail::vfs_router);

    // Extract native window ID (WebUI stores it as the first field)
    size_t id = *reinterpret_cast<size_t *>(&win);

    // ALLOW PUBLIC ACCESS
    webui_set_public(id, true);

    // Start server
    const char *url = webui_start_server(id, file.c_str());
    if (!url)
        return {};

    return std::string(url);
}

// Usage
start_server(window_, "index.html");

Key detail:
The default-page behavior depends entirely on the wrapper implementing VFS routing – e.g. in this wrapper:

static std::string g_start_page = "index.html";

static const void *vfs_router(const char *filename, int *length)
{
    if (strcmp(filename, "/") == 0) {
        static thread_local std::string tmp;
        tmp = "/" + g_start_page;
        filename = tmp.c_str();
    }
    return vfs(filename, length);
}

But for example, Python wrapper has no mechanism to override this, therefore default behavior must be implemented in WebUI core to be consistent across languages.

Request:
Add automatic serving of the configured start page when / is requested, so that entering IP:PORT loads the UI without requiring /index.html.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions