360 Secure SkillHub
360 安全技能中心

Static Server

通过内置 Python 脚本在本地启动静态文件 HTTP 服务器,接收文件或目录路径与可选端口参数,打印本地访问地址、所服务目录和停止说明;用于预览静态 HTML 页面、规避浏览器对 file:// 协议的限制,并可配合浏览器工具进行页面测试与截图。

liujintao-2021
liujintao-2021
热度 74.43
最近更新 2026-05-17 13:19:05
分类:开发依赖:代码执行 / 读写文件 / 联网浏览搜索应用场景:DevOps / 自动化脚本

安装技能

复制下面的话术发给你的 Agent,它会通过 secure-skills 检索并安装该技能。

执行命令安装此 skill: npx secure-skills-cli add static-server
Metadata
name
static-server
description
Start a local HTTP server to preview static HTML pages. Use when testing static pages, previewing HTML files, or when browser tools cannot access file:// URLs. Provides localhost URL for browser testing.

Static Server

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 <path> [--port PORT]

Arguments:

  • <path>: 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:

  1. Start server with exec (background mode)
  2. Use the localhost URL with browser tools
  3. Complete testing
  4. 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.