chore: air hot-reload + configurable backend port for dev proxy

This commit is contained in:
Pi Agent
2026-09-02 16:13:36 +00:00
parent 887d45a771
commit 681adda585
4 changed files with 37 additions and 6 deletions
+20
View File
@@ -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
+2
View File
@@ -2,3 +2,5 @@ bin/
dist/ dist/
node_modules/ node_modules/
.DS_Store .DS_Store
tmp/
air.log
+10 -5
View File
@@ -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 proto: ## Regenerate Go + TS code from proto
PATH="$(shell go env GOPATH)/bin:$$PATH" protoc \ 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) 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 CGO_ENABLED=0 go build -o bin/hub-api ./server
dev: ## Dev: Go server + Vite on :5173 (use http://localhost:5173) dev: ## Dev: Go server + Vite on :5173 (use http://localhost:5173); PORT=8081 make dev для второй копии
go run ./server & cd web && pnpm dev PORT=$(PORT) go run ./server & cd web && BACKEND_PORT=$(PORT) pnpm dev
dev-srv: dev-srv:
go run ./server PORT=$(PORT) go run ./server
dev-web: 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 test: ## Smoke-test the RPC endpoints
@go build -o bin/hub-api ./server @go build -o bin/hub-api ./server
+5 -1
View File
@@ -2,12 +2,16 @@ import { defineConfig } from "vite";
import preact from "@preact/preset-vite"; import preact from "@preact/preset-vite";
import tailwindcss from "@tailwindcss/vite"; import tailwindcss from "@tailwindcss/vite";
// Бэк для дев-прокси выбирается портом, не правкой кода:
// BACKEND_PORT=8081 pnpm dev -> прокси на вторую (рабочую/дев) копию.
const apiTarget = `http://localhost:${process.env.BACKEND_PORT ?? 8080}`;
export default defineConfig({ export default defineConfig({
plugins: [preact(), tailwindcss()], plugins: [preact(), tailwindcss()],
server: { server: {
proxy: { proxy: {
// Connect RPC calls in dev go straight to the Go server. // Connect RPC calls in dev go straight to the Go server.
"/homelab.v1.HomelabService": "http://localhost:8080", "/homelab.v1.HomelabService": apiTarget,
}, },
}, },
}); });