File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -28,7 +28,13 @@ interface ApiError {
2828
2929export const useApi = ( ) => {
3030 const config = useRuntimeConfig ( )
31- const baseUrl = config . public . apiBase || 'http://127.0.0.1:5214/api/v1'
31+ // Dual base: SSR (in-container) uses the docker service URL (apiBaseSsr);
32+ // the browser uses the host-port public URL. apiBaseSsr is empty outside
33+ // docker → falls back to public.apiBase.
34+ const baseUrl =
35+ ( import . meta. server && config . apiBaseSsr
36+ ? ( config . apiBaseSsr as string )
37+ : config . public . apiBase ) || 'http://127.0.0.1:5214/api/v1'
3238
3339 // `credentials: 'include'` only attaches the session cookie in the BROWSER.
3440 // During SSR (Nuxt server) there is no cookie jar, so an auth-gated
Original file line number Diff line number Diff line change @@ -9,7 +9,9 @@ interface ApiEnvelope<T> {
99
1010const route = useRoute ()
1111const config = useRuntimeConfig ()
12- const baseUrl = config .public .apiBase as string
12+ const baseUrl = (import .meta .server && config .apiBaseSsr
13+ ? config .apiBaseSsr
14+ : config .public .apiBase ) as string
1315
1416const slugParam = computed (() => {
1517 const raw = route .params .slug
Original file line number Diff line number Diff line change @@ -20,7 +20,9 @@ interface ApiEnvelope<T> {
2020}
2121
2222const config = useRuntimeConfig ()
23- const baseUrl = config .public .apiBase as string
23+ const baseUrl = (import .meta .server && config .apiBaseSsr
24+ ? config .apiBaseSsr
25+ : config .public .apiBase ) as string
2426
2527const { data : response } = await useFetch <ApiEnvelope <KunPostsResponse >>(
2628 ` ${baseUrl }/about/posts ` ,
Original file line number Diff line number Diff line change @@ -92,6 +92,13 @@ export default defineNuxtConfig({
9292 } ,
9393
9494 runtimeConfig : {
95+ // SSR runs inside the docker container, where the Go API is reachable by
96+ // its compose service name (api:5214) — NOT by the browser's host-port URL
97+ // (localhost:15010 is the container's own loopback). The browser can't
98+ // resolve `api`, so it keeps using public.apiBase. Set
99+ // NUXT_API_BASE_SSR=http://api:5214/api/v1 in docker; leave empty for local
100+ // air dev (the dual-base reader falls back to public.apiBase).
101+ apiBaseSsr : process . env . NUXT_API_BASE_SSR || '' ,
95102 public : {
96103 // 本项目 Go Fiber API(不是 鲲 Galgame OAuth)。Go 端口从 apps/api/.env 的 KUN_SERVER_PORT 读,dev 默认 5214。
97104 apiBase :
Original file line number Diff line number Diff line change @@ -30,5 +30,12 @@ RUN CGO_ENABLED=0 GOOS=linux go build -trimpath -ldflags="-s -w" \
3030# HEALTHCHECK, since distroless has no shell/wget. Ports live in compose.
3131FROM gcr.io/distroless/static-debian13:nonroot
3232COPY --from=build /out/app /app
33+ # About-page content: the static .mdx posts that cmd/server reads at runtime
34+ # (internal/about, cfg.About.PostsDir). They live in the WEB app's source tree
35+ # (apps/web/posts) and are NOT DB data, so no migration step carries them —
36+ # bake them into the api image so it is self-contained. Point the server at
37+ # them with KUN_POSTS_DIR=/posts (docker/api.env). The banner images under
38+ # apps/web/public/posts are served separately by the web container.
39+ COPY apps/web/posts /posts
3340USER nonroot:nonroot
3441ENTRYPOINT ["/app" ]
You can’t perform that action at this time.
0 commit comments