Skip to content

feat: add native subpath support via server.path_prefix#168

Open
ajinfajrian wants to merge 2 commits into
valeriansaliou:masterfrom
ajinfajrian:feat/subpath-support
Open

feat: add native subpath support via server.path_prefix#168
ajinfajrian wants to merge 2 commits into
valeriansaliou:masterfrom
ajinfajrian:feat/subpath-support

Conversation

@ajinfajrian

Copy link
Copy Markdown
Contributor

Context & Motivation

Currently, Vigil is hardcoded to run at the root of a domain (e.g., https://status.example.com/ ). Running it under a subpath (e.g., https://example.com/status ) is not fully supported because static assets, templates, manager API endpoints, and JavaScript requests assume they own the domain root.

This PR adds native subpath support via a new optional path_prefix configuration key under the [server] block.

Live Demonstration

A live demonstration of this feature in action can be viewed at:
https://ajinf.my.id/status (where all routes, stylesheets, fonts, logo links, and AJAX polling calls successfully resolve under the /status subpath directory).

Summary of Changes

  1. Config Option: Added an optional path_prefix string parameter in the [server] config block.
  2. Backend Route Scoping: If a path_prefix is configured, Actix-Web routes and MCP services are mounted under a web::scope(&prefix) . The trimmed scope root path ( "" ) is also mapped to the main index handler to handle trailing slash normalizations correctly.
  3. Template Context: Normalized the prefix and passed it to the Tera templates context ( config.path_prefix ).
  4. Front-End Prefixing:
    • Prepended config.path_prefix to the logo, stylesheets, and javascript links in index.tera .
    • Exposed window.PATH_PREFIX to the frontend JavaScript.
    • Prepended window.PATH_PREFIX to the frontend AJAX polling endpoints in index.js .
  5. Asset Path Resolution: Converted hardcoded root-relative URLs ( /assets/... ) inside common.css to relative paths ( ../... ) so fonts and badge icons resolve correctly under any custom subpath directory.
  6. Docs: Added path_prefix documentation to config.cfg and README.md .

Backward Compatibility

• If path_prefix is unset or set to an empty string (the default), the behavior remains byte-for-byte identical to the current root-relative deployment setup.
• Existing deployments will not notice any change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant