详细分析 ▾
- even though it advertises 'localhost'. If you only want local access, modify the bind to 127.0.0.1 (e.g., socketserver.TCPServer(('127.0.0.1', port), Handler)) or use an equivalent API that allows binding to localhost. - Do not serve directories containing secrets (SSH keys, config files, .env files). The server serves the whole directory tree you point it at. - Run as an unprivileged user and pick a non-conflicting port. Confirm your firewall or NAT does not forward the chosen port to the public internet. - If you cannot change the script, prefer running it from a dedicated temporary directory containing only files you intend to expose. If you accept the small change to bind only to localhost and follow the precautions above, the skill is reasonable for local static previewing. Otherwise, treat it as potentially exposing files on your local network.
运行时依赖
版本
Initial release: Python HTTP server for static HTML preview
安装命令 点击复制
技能文档
Start a Python HTTP server to preview static HTML files in a browser.
When to Use
- Testing static HTML pages
- Previewing web pages before deployment
- When browser tools block
file://protocol - Need a localhost URL for browser automation
Quick Start
Use the bundled script to start a server:
python scripts/serve.py [--port PORT]
Arguments:
: File path (serves parent directory) or directory path--port: Optional port number (default: 8000)
Examples:
# Serve a specific HTML file
python scripts/serve.py /path/to/index.html# Serve a directory
python scripts/serve.py /path/to/project
# Use custom port
python scripts/serve.py /path/to/index.html --port 9000
Output
The script prints:
- Access URL:
http://localhost:PORT/filename.html - Directory being served
- Instructions to stop (Ctrl+C)
Usage in Testing
When testing static pages with browser tools:
- Start server with
exec(background mode) - Use the localhost URL with browser tools
- Complete testing
- Kill the server process
Example workflow:
// 1. Start server in background
exec({
command: "python scripts/serve.py /path/to/index.html --port 8888",
background: true
})// 2. Open in browser
browser({
action: "open",
targetUrl: "http://localhost:8888/index.html"
})
// 3. Test and screenshot
browser({ action: "screenshot", fullPage: true })
// 4. Clean up
process({ action: "kill", sessionId: "..." })
browser({ action: "close" })
Alternative: One-liner
For quick testing without the script:
python -m http.server 8000 --directory /path/to/dir
Note: This serves the directory root, not a specific file.
免费技能或插件可能存在安全风险,如需更匹配、更安全的方案,建议联系付费定制