-
-
Notifications
You must be signed in to change notification settings - Fork 3
Static File Serving
github-actions edited this page May 15, 2026
·
4 revisions
Configure UNCORS to serve static files from local directories. This feature is useful for:
- Running local Single-Page Applications (SPAs)
- Overriding specific assets from remote servers
- Testing UI changes without deploying
- Serving custom resources during development
Static file configuration is defined per mapping:
mappings:
- from: ...
to: ...
statics:
- path: /assets
dir: ~/project/assets
index: index.html
- path: /static
dir: ~/project/data| Property | Type | Required | Description |
|---|---|---|---|
path |
string | Yes | URL path prefix for serving files (wildcards not supported) |
dir |
string | Yes | Local directory path containing files to serve |
index |
string | No | Fallback file when requested file not found (relative to dir) |
Request handling behavior:
- Requests matching the
pathprefix are served from the localdir - If a file exists locally, it is served immediately
- If a file does not exist and
indexis set, the index file is served (SPA mode) - If a file does not exist and
indexis not set, the request is forwarded upstream (proxy mode)
Single-Page Application (SPA) mode serves a fallback file for all unmatched requests. This is essential for client-side routing frameworks like React Router, Vue Router, or Angular Router.
How it works:
- Requests matching the
pathprefix are checked against local files - If a file exists (e.g.,
/app/bundle.js), it is served directly - If no file exists (e.g.,
/app/users/123), theindexfile is returned - The SPA's JavaScript router handles the URL and renders the appropriate view
Configuration:
mappings:
- from: ...
to: ...
statics:
- path: /app
dir: ~/project/dist
index: index.htmlUse cases:
- Serving a built React, Vue, or Angular application
- Local development with client-side routing
- Testing production builds locally
Proxy mode serves local files when they exist, but forwards unmatched requests to the upstream server or mock handlers.
How it works:
- Requests matching the
pathprefix are checked against local files - If a file exists locally, it is served from
dir - If no file exists, the request passes to the next handler (mock or upstream)
Configuration:
mappings:
- from: http://localhost
to: https://api.example.com
statics:
- path: /assets
dir: ~/project/distUse cases:
- Overriding specific assets (stylesheets, images, JavaScript)
- Testing local modifications without deploying
- Mixing local and remote resources
mappings:
- from: http://localhost
to: https://example.com
statics:
- path: /app
dir: ~/project/dist
index: index.html
- path: /docs
dir: ~/project/documentation
- path: /images
dir: ~/project/assets/imgmappings:
- from: http://localhost:3000
to: https://api.example.com
statics:
- path: /
dir: ~/my-app/build
index: index.html
mocks:
- path: /api/health
response:
code: 200
raw: '{"status": "ok"}'In this configuration:
- SPA files are served from the root path
/ - The
/api/healthendpoint is mocked - All other
/api/*requests are proxied tohttps://api.example.com