From 681adda58556c9b9a7071a156ff91d95154760cb Mon Sep 17 00:00:00 2001 From: Pi Agent Date: Wed, 2 Sep 2026 16:13:36 +0000 Subject: [PATCH] chore: air hot-reload + configurable backend port for dev proxy --- .air.toml | 20 ++++++++++++++++++++ .gitignore | 2 ++ Makefile | 15 ++++++++++----- web/vite.config.ts | 6 +++++- 4 files changed, 37 insertions(+), 6 deletions(-) create mode 100644 .air.toml diff --git a/.air.toml b/.air.toml new file mode 100644 index 0000000..a4d9655 --- /dev/null +++ b/.air.toml @@ -0,0 +1,20 @@ +root = "." +tmp_dir = "tmp" + +[build] +# отдельный бинарь, чтобы не путать с make server (bin/hub-api) +cmd = "go build -o ./bin/hub-api-dev ./server" +bin = "./bin/hub-api-dev" +include_ext = ["go"] +exclude_dir = ["web", "dist", "gen", "bin", "tmp", "proto", "docs"] +# порт берётся из env PORT самим сервером: PORT=8081 air +delay = 500 +stop_on_error = true +send_interrupt = true +kill_delay = "2s" + +[log] +time = true + +[misc] +clean_on_exit = true diff --git a/.gitignore b/.gitignore index c3fd08d..0b78a50 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,5 @@ bin/ dist/ node_modules/ .DS_Store +tmp/ +air.log diff --git a/Makefile b/Makefile index 9969696..0330304 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,6 @@ -.PHONY: proto web server release dev test +PORT ?= 8080 # порт бэка; в dev еще прокидывается в vite-прокси (BACKEND_PORT) + +.PHONY: proto web server release dev dev-srv dev-web watch test proto: ## Regenerate Go + TS code from proto PATH="$(shell go env GOPATH)/bin:$$PATH" protoc \ @@ -18,14 +20,17 @@ server: ## Build Go binary → bin/hub-api release: ## CI build: static binary for the box (run on the box itself, native arch) CGO_ENABLED=0 go build -o bin/hub-api ./server -dev: ## Dev: Go server + Vite on :5173 (use http://localhost:5173) - go run ./server & cd web && pnpm dev +dev: ## Dev: Go server + Vite on :5173 (use http://localhost:5173); PORT=8081 make dev для второй копии + PORT=$(PORT) go run ./server & cd web && BACKEND_PORT=$(PORT) pnpm dev dev-srv: - go run ./server + PORT=$(PORT) go run ./server dev-web: - cd web && pnpm dev + cd web && BACKEND_PORT=$(PORT) pnpm dev + +watch: ## Hot-reload сервера (air); порт как у dev: PORT=8081 make watch + PORT=$(PORT) air test: ## Smoke-test the RPC endpoints @go build -o bin/hub-api ./server diff --git a/web/vite.config.ts b/web/vite.config.ts index 38f980e..02efba9 100644 --- a/web/vite.config.ts +++ b/web/vite.config.ts @@ -2,12 +2,16 @@ import { defineConfig } from "vite"; import preact from "@preact/preset-vite"; import tailwindcss from "@tailwindcss/vite"; +// Бэк для дев-прокси выбирается портом, не правкой кода: +// BACKEND_PORT=8081 pnpm dev -> прокси на вторую (рабочую/дев) копию. +const apiTarget = `http://localhost:${process.env.BACKEND_PORT ?? 8080}`; + export default defineConfig({ plugins: [preact(), tailwindcss()], server: { proxy: { // Connect RPC calls in dev go straight to the Go server. - "/homelab.v1.HomelabService": "http://localhost:8080", + "/homelab.v1.HomelabService": apiTarget, }, }, });