add static-hosting
This commit is contained in:
parent
f6e8f569ed
commit
cc934e987a
79
skills/linggan/static-hosting/SKILL.md
Normal file
79
skills/linggan/static-hosting/SKILL.md
Normal file
@ -0,0 +1,79 @@
|
|||||||
|
---
|
||||||
|
name: static-hosting
|
||||||
|
description: Serve static HTML/CSS/JS/images from robot project directories via the built-in FastAPI static file server. Use when generating web pages, reports, or interactive content for a bot.
|
||||||
|
---
|
||||||
|
|
||||||
|
# Static Hosting
|
||||||
|
|
||||||
|
Provide external access to static files (HTML, CSS, JS, images, fonts, etc.) stored under each robot's project directory.
|
||||||
|
|
||||||
|
## Use when
|
||||||
|
|
||||||
|
- Generate HTML pages, reports, or dashboards for a bot and need a URL to access them
|
||||||
|
- 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
|
||||||
|
|
||||||
|
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`.
|
||||||
|
|
||||||
|
## 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
|
||||||
|
|
||||||
|
```
|
||||||
|
/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
|
||||||
|
|
||||||
|
- Content-Type is auto-detected from file extension
|
||||||
|
- CORS is already configured (allow all origins) so frontend JS can fetch APIs on the same server
|
||||||
|
- Subdirectories of any depth are supported
|
||||||
|
- No authentication — all files under `/robots/` are publicly accessible
|
||||||
|
- The mount is defined in `fastapi_app.py`
|
||||||
Loading…
Reference in New Issue
Block a user