Files
SoundGame/web/serve.sh
T

42 lines
1.8 KiB
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/bin/bash
# serve.sh — 本地托管 SoundGame Web 站点(含用户系统 API)
#
# 用法:
# bash web/serve.sh (或 chmod +x 后 ./web/serve.sh)
#
# 手机访问:手机与电脑连**同一 WiFi**,浏览器打开下面打印的局域网地址
# (WSL2 用户注意:若手机无法访问 WSL2 的 IP,需在 Windows 侧做端口转发:
# netsh interface portproxy add v4tov4 listenport=8000 listenaddress=0.0.0.0 connectport=8000 connectaddress=<WSL_IP>
# 然后用 Windows 主机的局域网 IP 访问)。
#
# 服务器:web/server/server.js(Node 零依赖),静态托管 web/ + JSON API:
# POST /api/register {username, pin} 注册(PIN 为 4~6 位数字)
# POST /api/login {username, pin} 登录 → { token }
# GET /api/progress?game=xxx 读进度(Bearer token)
# PUT /api/progress {game, data} 写进度(Bearer token)
# 数据落盘 web/server/data/,端口用 env PORT 覆盖(默认 8000)。
# 详见 web/server/README.md。
IP=$(hostname -I | awk '{print $1}')
PORT=${PORT:-8000}
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
# node 解析顺序:项目自带 tools/node → PATH 中的 node
if [ -x "$ROOT/tools/node/bin/node" ]; then
NODE="$ROOT/tools/node/bin/node"
else
NODE="$(command -v node)"
fi
echo "================================================"
echo " SoundGame Web 本地服务器(静态 + 用户系统 API)"
echo " 本机访问: http://localhost:${PORT}/"
echo " 局域网访问: http://${IP}:${PORT}/ <- 手机浏览器开这个"
echo " 游戏大厅在根路径,模板游戏: /template/"
echo " API: /api/register /api/login /api/progress"
echo " 手机需与电脑在同一 WiFi"
echo " Ctrl+C 停止"
echo "================================================"
exec "$NODE" "$ROOT/web/server/server.js"