static-hosting
This commit is contained in:
parent
8cad98daa1
commit
a1754feaf3
@ -5,75 +5,25 @@ description: Serve static HTML/CSS/JS/images from robot project directories via
|
|||||||
|
|
||||||
# Static Hosting
|
# Static Hosting
|
||||||
|
|
||||||
Provide external access to static files (HTML, CSS, JS, images, fonts, etc.) stored under each robot's project directory.
|
Host static files (HTML, CSS, JS, images, fonts, etc.) under the bot's project directory and get public URLs.
|
||||||
|
|
||||||
## Use when
|
## Usage
|
||||||
|
|
||||||
- Generate HTML pages, reports, or dashboards for a bot and need a URL to access them
|
Write files to `/app/projects/robot/{ASSISTANT_ID}/`, then run the script to get the public URL:
|
||||||
- Create interactive web content (with CSS/JS) that users can open in a browser
|
|
||||||
- Need to host images or other assets referenced by bot-generated HTML
|
|
||||||
|
|
||||||
## How it works
|
```bash
|
||||||
|
python3 {SKILL_DIR}/scripts/get_url.py <absolute_path>
|
||||||
FastAPI mounts `projects/robot/` at the `/robots` URL path with `html=True` enabled.
|
|
||||||
|
|
||||||
```
|
|
||||||
/app/projects/robot/{bot_id}/ --> {FASTAPI_URL}/robots/{bot_id}/
|
|
||||||
/app/projects/robot/{bot_id}/foo.html --> {FASTAPI_URL}/robots/{bot_id}/foo.html
|
|
||||||
```
|
```
|
||||||
|
|
||||||
`FASTAPI_URL` : `https://engine.aitravelmaster.com`.
|
Example:
|
||||||
|
|
||||||
## URL rules
|
|
||||||
|
|
||||||
| Local path | External URL | Notes |
|
|
||||||
|---|---|---|
|
|
||||||
| `/app/projects/robot/{bot_id}/index.html` | `/robots/{bot_id}/` | `html=True` auto-resolves `index.html` |
|
|
||||||
| `/app/projects/robot/{bot_id}/page.html` | `/robots/{bot_id}/page.html` | Direct HTML access |
|
|
||||||
| `/app/projects/robot/{bot_id}/css/style.css` | `/robots/{bot_id}/css/style.css` | CSS files |
|
|
||||||
| `/app/projects/robot/{bot_id}/js/app.js` | `/robots/{bot_id}/js/app.js` | JavaScript files |
|
|
||||||
| `/app/projects/robot/{bot_id}/images/logo.png` | `/robots/{bot_id}/images/logo.png` | Images (png/jpg/svg/etc.) |
|
|
||||||
| `/app/projects/robot/{bot_id}/fonts/custom.woff2` | `/robots/{bot_id}/fonts/custom.woff2` | Font files |
|
|
||||||
|
|
||||||
## Recommended directory structure
|
|
||||||
|
|
||||||
|
```bash
|
||||||
|
python3 {SKILL_DIR}/scripts/get_url.py /app/projects/robot/{ASSISTANT_ID}/index.html
|
||||||
|
# => https://engine.aitravelmaster.com/robots/[bot-id]/index.html
|
||||||
```
|
```
|
||||||
/app/projects/robot/{bot_id}/
|
|
||||||
├── index.html # Entry page (auto-served at /robots/{bot_id}/)
|
|
||||||
├── css/
|
|
||||||
│ └── style.css
|
|
||||||
├── js/
|
|
||||||
│ └── app.js
|
|
||||||
├── images/
|
|
||||||
│ └── logo.png
|
|
||||||
└── fonts/
|
|
||||||
└── custom.woff2
|
|
||||||
```
|
|
||||||
|
|
||||||
## HTML referencing rules
|
|
||||||
|
|
||||||
Inside HTML files, use **relative paths** to reference local assets:
|
|
||||||
|
|
||||||
```html
|
|
||||||
<!-- In projects/robot/{bot_id}/index.html -->
|
|
||||||
<link rel="stylesheet" href="css/style.css">
|
|
||||||
<script src="js/app.js"></script>
|
|
||||||
<img src="images/logo.png" alt="logo">
|
|
||||||
```
|
|
||||||
|
|
||||||
Do NOT use absolute paths like `/css/style.css` — this would resolve to the server root, not the bot directory.
|
|
||||||
|
|
||||||
## Quick example
|
|
||||||
|
|
||||||
To generate and serve a simple page for bot `63069654-7750-409d-9a58-a0960d899a20`:
|
|
||||||
|
|
||||||
1. Write HTML to `/app/projects/robot/63069654-7750-409d-9a58-a0960d899a20/index.html`
|
|
||||||
2. Access at `{FASTAPI_URL}/robots/63069654-7750-409d-9a58-a0960d899a20/`
|
|
||||||
|
|
||||||
## Notes
|
## Notes
|
||||||
|
|
||||||
- Content-Type is auto-detected from file extension
|
- Inside HTML, use **relative paths** to reference other assets (e.g. `href="css/style.css"`)
|
||||||
- CORS is already configured (allow all origins) so frontend JS can fetch APIs on the same server
|
- `index.html` is auto-served at the directory URL
|
||||||
- Subdirectories of any depth are supported
|
- All files under `/robots/` are publicly accessible, no authentication
|
||||||
- No authentication — all files under `/robots/` are publicly accessible
|
|
||||||
- The mount is defined in `fastapi_app.py`
|
|
||||||
|
|||||||
25
skills/linggan/static-hosting/scripts/get_url.py
Normal file
25
skills/linggan/static-hosting/scripts/get_url.py
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
import os
|
||||||
|
import sys
|
||||||
|
|
||||||
|
FASTAPI_URL = os.getenv("FASTAPI_URL", "https://engine.aitravelmaster.com")
|
||||||
|
ASSISTANT_ID = os.getenv("ASSISTANT_ID", "")
|
||||||
|
|
||||||
|
if not ASSISTANT_ID:
|
||||||
|
print("Error: ASSISTANT_ID environment variable is not set")
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
if len(sys.argv) < 2:
|
||||||
|
print(f"Usage: python3 {sys.argv[0]} <file_path>")
|
||||||
|
print(f"Example: python3 {sys.argv[0]} /app/projects/robot/{ASSISTANT_ID}/index.html")
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
file_path = os.path.abspath(sys.argv[1])
|
||||||
|
|
||||||
|
workspace_root = f"/app/projects/robot/{ASSISTANT_ID}"
|
||||||
|
if not file_path.startswith(workspace_root):
|
||||||
|
print(f"Error: path must be under {workspace_root}, got: {file_path}")
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
relative_path = file_path[len(workspace_root):] # e.g. "/css/style.css"
|
||||||
|
base_url = f"{FASTAPI_URL.rstrip('/')}/robots/{ASSISTANT_ID}"
|
||||||
|
print(f"{base_url}{relative_path}")
|
||||||
Loading…
Reference in New Issue
Block a user