chore: air hot-reload + configurable backend port for dev proxy
This commit is contained in:
@@ -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,3 +2,5 @@ bin/
|
||||
dist/
|
||||
node_modules/
|
||||
.DS_Store
|
||||
tmp/
|
||||
air.log
|
||||
|
||||
@@ -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
|
||||
|
||||
+5
-1
@@ -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,
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user