diff --git a/README.md b/README.md index d4a4526..e272ace 100644 --- a/README.md +++ b/README.md @@ -21,14 +21,33 @@ Open: http://localhost:5173 ``` +## Click To Run + +If you want a one-click launcher on macOS/Linux: + +```bash +./start.sh +``` + +Stop the background server with: + +```bash +./stop.sh +``` + +If you run the server in the foreground, stop it with `Ctrl+C`. + ## Notes - Login calls the upstream API from `project-specs/API_ENDPOINTS.md`. - If the upstream login rejects the credentials or is unavailable, demo mode creates a local session so the UI can still be exercised. - Order search, order detail helpers, FPP loading, password change, and special message save are wired through the API adapter with mock fallback for local preview. +- `start.sh` writes a pid file named `.doclink-web.pid` and a log file named `doclink-web.log`. ## Main Files - `server.js` - `styles.css` - `package.json` +- `start.sh` +- `stop.sh` diff --git a/start.sh b/start.sh new file mode 100755 index 0000000..bff14ec --- /dev/null +++ b/start.sh @@ -0,0 +1,21 @@ +#!/usr/bin/env bash +set -euo pipefail + +ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +PID_FILE="$ROOT_DIR/.doclink-web.pid" +LOG_FILE="$ROOT_DIR/doclink-web.log" +PORT="${PORT:-5198}" + +if [[ -f "$PID_FILE" ]]; then + OLD_PID="$(cat "$PID_FILE" 2>/dev/null || true)" + if [[ -n "${OLD_PID:-}" ]] && kill -0 "$OLD_PID" 2>/dev/null; then + echo "DocLink Web is already running on pid $OLD_PID" + exit 0 + fi + rm -f "$PID_FILE" +fi + +nohup env PORT="$PORT" node "$ROOT_DIR/server.js" >"$LOG_FILE" 2>&1 & +echo $! > "$PID_FILE" +echo "DocLink Web started on http://localhost:$PORT" +echo "PID: $(cat "$PID_FILE")" diff --git a/stop.sh b/stop.sh new file mode 100755 index 0000000..25d7404 --- /dev/null +++ b/stop.sh @@ -0,0 +1,26 @@ +#!/usr/bin/env bash +set -euo pipefail + +ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +PID_FILE="$ROOT_DIR/.doclink-web.pid" + +if [[ ! -f "$PID_FILE" ]]; then + echo "No pid file found. If the server is running in another terminal, stop it with Ctrl+C." + exit 0 +fi + +PID="$(cat "$PID_FILE" 2>/dev/null || true)" +if [[ -z "${PID:-}" ]]; then + rm -f "$PID_FILE" + echo "Pid file was empty. Removed it." + exit 0 +fi + +if kill -0 "$PID" 2>/dev/null; then + kill "$PID" + echo "Stopped DocLink Web process $PID" +else + echo "Process $PID is not running anymore." +fi + +rm -f "$PID_FILE"