httpStatics
Official sources are open to Staxis GitLab group members: how to join and view the code.
Repository:
httpStatics development
Versions:
tags
and releases
Description
httpStatics serves files from the project's public folders through serverApp. Its label and typology are both httpStatics. It combines public-file delivery, URL handling, PPM deny rules, and optional cooperation with httpCompression. Normal use is automatic: configure the folders and let the layer attach.
Read before flight
-
We suggest keeping only intentionally public files inside the served roots. Keep keys, private data, and server-side sources outside them; review symbolic links and their targets. Deny patterns complement that file layout.
-
We suggest checking both the root URL and direct public-folder URLs when arranging frontoffice files. The frontoffice directory is served first at / and also remains reachable through its path below the public root.
-
We suggest verifying index handling, redirects, cache headers, and actual Content-Encoding on your selected runtime. Choose one compression owner and validate transformed content as described in httpCompression.
Requirements and Installation
The manifest declares serverApp as its required pack. The implementation also uses the ppm library for publicDeny matching: keep ppm available before httpStatics. Native Node.js delivery needs no extra npm package. Install through the Manager:
manager -> install -> httpStatics
Put ppm in the library group, serverApp and httpShield before this pack, and httpListener after the prepared application. If used, put httpCompression before httpStatics as well. The supplied serverApp and httpCompression manifests already permit httpStatics's pack label. Prepare project keys and integrity records. No consumer Vault request to httpStatics itself is needed to serve files.
Optional delivery paths use express.static from Express, koa-static for Koa, or @fastify/static for Fastify. The pack enables the global Guardian allowBareDeps option and declares those package names. Its file-access rule covers the supplied public folder; update the rule when changing that root.
Files Map
| File | Purpose |
|---|---|
| manifest.json | Declares the pack identity and serverApp requirement. |
| configs.js | Provides folder names, serving options, and Guardian rules. |
| main.js | Mounts the frontoffice and public roots on the selected runtime. |
| README.md | Contains the pack reference. |
Configuration
In the project's config.js, serving options belong to config.serveropt, folder names to config.serveropt.folders, and file-access rules to config.engineopt.guard.allowedFileAccess. Merge these branches into the exported config object while preserving other folders and rules. This example selects plain serving; the supplied pack default is serveStatic='compressed'.
// config.js -> config (merge into the exported object)
engineopt: {
guard: {
allowedFileAccess: [
{
pack: 'httpStatics', // Pack label used by Guardian
roots: ['./server-public', './server-public/*']
}
]
}
},
serveropt: {
folders: {
public: 'server-public',
backoffice: 'backoffice',
frontoffice: 'frontoffice',
apis: 'server-apis'
},
notrailsurl: true,
safeindex: true,
serveStatic: true,
publicDeny: ['.*', '.*/*']
}
| Option under config.serveropt | Behaviour |
|---|---|
| folders.public | Public root, resolved from engine.baseroot |
| folders.frontoffice | Frontoffice subdirectory, resolved beneath the public root |
| folders.backoffice, folders.apis | Shared configuration fields; this pack does not mount them separately |
| serveStatic=false | Skips mounting static handlers during attach |
| serveStatic=true | Mounts plain static delivery |
| serveStatic='compressed' | Also requests the available httpCompression bundle and passes its cache options to the static adapter |
| safeindex | Selects index candidates and adapter-specific directory handling |
| notrailsurl | Adds a trailing-slash redirect after the static handlers |
| publicDeny | PPM rules used to exclude matching requests from static delivery |
backoffice is a folder name, not an authentication boundary. A directory placed under the public root remains part of that root unless separately excluded. Keep the configured public and frontoffice locations inside the directory scope you intend to expose.
Public Layout and URL Mapping
project-root/
βββ server-public/
βββ frontoffice/
β βββ index.html
β βββ style.css
βββ logo.svg
The frontoffice root is mounted first, followed by the public root, both without a URL prefix. With this layout, / serves frontoffice/index.html, /style.css serves frontoffice/style.css, and /logo.svg falls through to server-public/logo.svg. If both roots contain a file at the same requested path, the frontoffice file wins. /frontoffice/style.css also resolves through the public root.
curl -i http://127.0.0.1:3000/
curl -I http://127.0.0.1:3000/style.css
curl -i http://127.0.0.1:3000/logo.svg
Adjust the address to your listener and create the files before testing. The native implementation streams GET responses and answers HEAD with file headers and no body. Unknown extensions use application/octet-stream. It does not implement directory listings or a general single-page application fallback.
Index Files and Redirects
safeindex=true supplies index.html, index.htm, and index as candidates. In native mode, lookup applies only to the root of each mount, so / can select an index while /docs/ does not automatically select docs/index.html. safeindex=false disables that native root lookup; explicit file URLs remain usable. Framework adapters delegate directory-index behaviour to their own static packages.
The notrailsurl handler runs after static serving. A remaining GET request ending in a slash, except /, receives a 301 redirect with one trailing slash removed and its query string preserved. Files already served by an earlier static handler do not reach that redirect. It does not handle HEAD requests. Test the combination with framework-specific directory redirects before deployment.
Public Deny Rules
publicDeny uses ppm patterns, distinct from httpShield's denyaccess rules. The default .* matches dot-prefixed path segments; path-mode rules containing / match complete paths and use * explicitly for wildcards. These patterns are not JavaScript regular expressions. Matching requests are excluded from this pack's static delivery.
A skipped or denied static request can continue to later application middleware. publicDeny is not a global authorization policy for all routes. Use application authorization and, where needed, httpShield path rules for their respective responsibilities.
Compression and Cache Cooperation
serveStatic='compressed' attempts to obtain httpCompression when it is present. Without an available bundle, serving continues with the basic options. In native mode, httpStatics does not mount compressor() or add gzip itself; select and validate a separate compression owner if needed. The native static handler sets Content-Type and Content-Length, but does not apply the bundle's cache options, ETag, Last-Modified, or conditional-request handling.
Express and Fastify receive the applicable static options through their packages. Koa receives its mapped index, hidden-file, and numeric maxage options; a string such as 7d is not passed as a numeric maxage there. Compression itself remains the responsibility of the selected middleware or framework plugin. Check actual response headers rather than inferring gzip or cache behaviour from the serveStatic value alone.
Documentation
This page is the HTML adaptation of the pack's README.md, with practical clarifications checked against the implementation. Complete Staxis onboarding to request GitLab access to the official sources.