Skip to content

feat(server): serve an optional static directory - #2456

Open
original4422 wants to merge 2 commits into
abetlen:mainfrom
original4422:feat/server-static-directory
Open

original4422 wants to merge 2 commits into
abetlen:mainfrom
original4422:feat/server-static-directory

Conversation

@original4422

Copy link
Copy Markdown

Summary

Add an optional --static_dir / STATIC_DIR / top-level config static_dir setting for serving a local HTML client and assets alongside the API. Static serving stays off by default.

existing API/docs routes → optional public static root

Fixes #1060. Directory requests can serve index.html; existing API routes take precedence. Static files are public even when api_key is set, while bearer checks on API routes remain unchanged. Starlette's default directory confinement is retained.

Evidence

  • Before: the original CLI rejects a static-directory option, and the original public server returns 404 for the root and assets while real model/native API controls work.
    After: four actual subprocess servers cover CLI, environment, JSON config and default-off behavior. All 12 HTTP/native cases pass, including public assets, traversal/external-symlink rejection, API routing, bearer 401/200 and real CPU completion.
  • make test with LLAMA_CPP_TEST_MODEL pointing to a local ggml-org stories15M-q4_0.gguf and PYTEST_ADDOPTS selecting test_server_static.py, test_llama_chat_format.py, test_llama_grammar.py and test_llama_speculative.py: 18 passed, no skips, including 12 new integrated regression cases. Native cases opt in through that variable and do not download weights.
  • make lint: Ruff checks and formatting pass for all 30 Python source/test files.

Validated on macOS arm64, Python 3.12.14, vendored llama.cpp f5e6915c2, with n_gpu_layers=0 and real model execution. The model-downloading test_llama.py suite, GPU platforms and performance were not tested.

Implemented and reviewed by Codex as the author's authorized agent.

Merge Danger

Door: two-way

Blast Radius: server

Only an explicitly configured directory is served; it must contain files intended for public access.

This branch has not been deployed

No deployments
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.

Support Static File Dir/Root Dir in Server

1 participant