Add vue-router, login/setup flow and backend logging
Refactor frontend to route-based navigation with vue-router, add system setup and login pages with API integration. Add structured logging, access-log middleware and startup lifecycle to FastAPI backend.
This commit is contained in:
176
web/start.sh
176
web/start.sh
@@ -1,14 +1,12 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
# ============================================================
|
||||
# X-Financial Reimbursement Admin - Start Script
|
||||
# ============================================================
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
cd "$SCRIPT_DIR"
|
||||
ROOT_DIR="$(cd "$SCRIPT_DIR/.." && pwd)"
|
||||
ROOT_ENV_FILE="$ROOT_DIR/.env"
|
||||
MODE="${1:-start}"
|
||||
|
||||
# Colors
|
||||
RED='\033[0;31m'
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[1;33m'
|
||||
@@ -18,22 +16,29 @@ info() { echo -e "${GREEN}[INFO]${NC} $*"; }
|
||||
warn() { echo -e "${YELLOW}[WARN]${NC} $*"; }
|
||||
error() { echo -e "${RED}[ERROR]${NC} $*"; exit 1; }
|
||||
|
||||
# ----------------------------------------------------------
|
||||
# Check Node.js
|
||||
# ----------------------------------------------------------
|
||||
if ! command -v node &>/dev/null; then
|
||||
error "Node.js is not installed. Install it first: https://nodejs.org"
|
||||
if [ -f "$ROOT_ENV_FILE" ]; then
|
||||
set -a
|
||||
. "$ROOT_ENV_FILE"
|
||||
set +a
|
||||
fi
|
||||
|
||||
if ! command -v npm &>/dev/null; then
|
||||
error "npm is not installed. It should come with Node.js."
|
||||
fi
|
||||
WEB_HOST="${WEB_HOST:-127.0.0.1}"
|
||||
WEB_PORT="${WEB_PORT:-5173}"
|
||||
|
||||
info "Node.js $(node -v) | npm $(npm -v)"
|
||||
export VITE_SETUP_COMPLETED="${SETUP_COMPLETED:-false}"
|
||||
export VITE_COMPANY_NAME="${COMPANY_NAME:-}"
|
||||
export VITE_COMPANY_CODE="${COMPANY_CODE:-}"
|
||||
export VITE_ADMIN_EMAIL="${ADMIN_EMAIL:-}"
|
||||
export VITE_WEB_HOST="${WEB_HOST}"
|
||||
export VITE_WEB_PORT="${WEB_PORT}"
|
||||
export VITE_SERVER_HOST="${SERVER_HOST:-127.0.0.1}"
|
||||
export VITE_SERVER_PORT="${SERVER_PORT:-8000}"
|
||||
export VITE_POSTGRES_HOST="${POSTGRES_HOST:-127.0.0.1}"
|
||||
export VITE_POSTGRES_PORT="${POSTGRES_PORT:-5432}"
|
||||
export VITE_POSTGRES_DB="${POSTGRES_DB:-x_financial}"
|
||||
export VITE_POSTGRES_USER="${POSTGRES_USER:-postgres}"
|
||||
export VITE_REDIS_URL="${REDIS_URL:-}"
|
||||
|
||||
# ----------------------------------------------------------
|
||||
# WSL on a Windows-mounted repo should reuse Windows Node
|
||||
# ----------------------------------------------------------
|
||||
is_wsl() {
|
||||
grep -qi microsoft /proc/version 2>/dev/null
|
||||
}
|
||||
@@ -45,42 +50,125 @@ is_windows_mount() {
|
||||
esac
|
||||
}
|
||||
|
||||
if is_wsl && is_windows_mount && command -v powershell.exe &>/dev/null && command -v wslpath &>/dev/null; then
|
||||
WIN_PATH="$(wslpath -w "$SCRIPT_DIR")"
|
||||
WIN_PATH_PS="${WIN_PATH//\'/\'\'}"
|
||||
info "Detected WSL on a Windows-mounted project"
|
||||
info "Using Windows npm to avoid cross-platform node_modules installs"
|
||||
info "Access: http://127.0.0.1:5173"
|
||||
echo ""
|
||||
exec powershell.exe -NoProfile -ExecutionPolicy Bypass -Command "Set-Location -LiteralPath '$WIN_PATH_PS'; npm start"
|
||||
fi
|
||||
use_windows_npm() {
|
||||
is_wsl && is_windows_mount && command -v powershell.exe >/dev/null 2>&1 && command -v wslpath >/dev/null 2>&1
|
||||
}
|
||||
|
||||
windows_project_path() {
|
||||
wslpath -w "$SCRIPT_DIR"
|
||||
}
|
||||
|
||||
run_windows_powershell() {
|
||||
local command="$1"
|
||||
powershell.exe -NoProfile -ExecutionPolicy Bypass -Command "$command"
|
||||
}
|
||||
|
||||
run_windows_npm_install() {
|
||||
local win_path
|
||||
local win_path_ps
|
||||
|
||||
win_path="$(windows_project_path)"
|
||||
win_path_ps="${win_path//\'/\'\'}"
|
||||
run_windows_powershell "Set-Location -LiteralPath '$win_path_ps'; npm install"
|
||||
}
|
||||
|
||||
run_windows_npm_start() {
|
||||
local win_path
|
||||
local win_path_ps
|
||||
|
||||
win_path="$(windows_project_path)"
|
||||
win_path_ps="${win_path//\'/\'\'}"
|
||||
exec powershell.exe -NoProfile -ExecutionPolicy Bypass -Command "Set-Location -LiteralPath '$win_path_ps'; npm start -- --host $WEB_HOST --port $WEB_PORT"
|
||||
}
|
||||
|
||||
# ----------------------------------------------------------
|
||||
# Install dependencies only when they are missing or unusable
|
||||
# ----------------------------------------------------------
|
||||
dependencies_ready() {
|
||||
[ -d "node_modules" ] || return 1
|
||||
[ -f "node_modules/vite/bin/vite.js" ] || return 1
|
||||
[ -e "node_modules/.bin/vite" ] || [ -e "node_modules/.bin/vite.cmd" ] || return 1
|
||||
[ -f "node_modules/pg/package.json" ] || return 1
|
||||
[ -f "node_modules/vue-router/package.json" ] || return 1
|
||||
|
||||
node -e "require('rollup')" >/dev/null 2>&1
|
||||
if use_windows_npm; then
|
||||
local win_path
|
||||
local win_path_ps
|
||||
|
||||
win_path="$(windows_project_path)"
|
||||
win_path_ps="${win_path//\'/\'\'}"
|
||||
powershell.exe -NoProfile -ExecutionPolicy Bypass -Command "Set-Location -LiteralPath '$win_path_ps'; node -e \"require('rollup'); require('pg'); require('vue-router')\"" >/dev/null 2>&1
|
||||
return $?
|
||||
fi
|
||||
|
||||
[ -e "node_modules/.bin/vite" ] || [ -e "node_modules/.bin/vite.cmd" ] || return 1
|
||||
node -e "require('rollup'); require('pg'); require('vue-router')" >/dev/null 2>&1
|
||||
}
|
||||
|
||||
if ! dependencies_ready; then
|
||||
warn "Dependencies are missing or incomplete"
|
||||
info "Running npm install..."
|
||||
npm install
|
||||
ensure_runtime_tools() {
|
||||
if use_windows_npm; then
|
||||
info "Detected WSL on a Windows-mounted project"
|
||||
info "Using Windows npm to manage web dependencies"
|
||||
|
||||
if ! run_windows_powershell "node -v > \$null; npm -v > \$null" >/dev/null 2>&1; then
|
||||
error "Windows Node.js/npm is not available in PATH. Install Node.js on Windows first."
|
||||
fi
|
||||
|
||||
return 0
|
||||
fi
|
||||
|
||||
if ! command -v node >/dev/null 2>&1; then
|
||||
error "Node.js is not installed. Install it first: https://nodejs.org"
|
||||
fi
|
||||
|
||||
if ! command -v npm >/dev/null 2>&1; then
|
||||
error "npm is not installed. It should come with Node.js."
|
||||
fi
|
||||
|
||||
info "Node.js $(node -v) | npm $(npm -v)"
|
||||
}
|
||||
|
||||
ensure_dependencies() {
|
||||
ensure_runtime_tools
|
||||
|
||||
if dependencies_ready; then
|
||||
info "Web dependencies are ready."
|
||||
return 0
|
||||
fi
|
||||
|
||||
warn "Web dependencies are missing or incomplete"
|
||||
info "Installing web dependencies..."
|
||||
|
||||
if use_windows_npm; then
|
||||
run_windows_npm_install
|
||||
else
|
||||
npm install
|
||||
fi
|
||||
|
||||
if ! dependencies_ready; then
|
||||
error "Dependencies are still incomplete after npm install. Try deleting node_modules and running npm install manually."
|
||||
error "Web dependencies are still incomplete after installation. Try deleting web/node_modules and running npm install manually."
|
||||
fi
|
||||
fi
|
||||
|
||||
# ----------------------------------------------------------
|
||||
# Start dev server
|
||||
# ----------------------------------------------------------
|
||||
info "Starting X-Financial Reimbursement Admin..."
|
||||
info "Access: http://127.0.0.1:5173"
|
||||
echo ""
|
||||
info "Web dependencies are ready."
|
||||
}
|
||||
|
||||
exec npm start
|
||||
start_dev_server() {
|
||||
info "Starting X-Financial Reimbursement Admin..."
|
||||
info "Access: http://$WEB_HOST:$WEB_PORT"
|
||||
echo ""
|
||||
|
||||
if use_windows_npm; then
|
||||
run_windows_npm_start
|
||||
fi
|
||||
|
||||
exec npm start -- --host "$WEB_HOST" --port "$WEB_PORT"
|
||||
}
|
||||
|
||||
case "$MODE" in
|
||||
deps)
|
||||
ensure_dependencies
|
||||
;;
|
||||
start)
|
||||
ensure_dependencies
|
||||
start_dev_server
|
||||
;;
|
||||
*)
|
||||
error "Unknown mode: $MODE. Use one of: deps, start"
|
||||
;;
|
||||
esac
|
||||
|
||||
Reference in New Issue
Block a user