Skip to content

Commit d881b0e

Browse files
committed
fix(api): default /js to bundled container asset
1 parent bc10ce0 commit d881b0e

6 files changed

Lines changed: 31 additions & 10 deletions

File tree

apps/api/.env.example

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
PORT=8080
22
REDIS_URL=
3-
SCRIPT_PATH=../web/public/js/client.min.js
43
DEBUG=false
4+
5+
# Optional override for the served /js asset path.
6+
# When unset, the API automatically uses the built-in container copy at
7+
# /app/public/js/client.min.js if present, otherwise it falls back to the
8+
# local source-run path at ../web/public/js/client.min.js.
9+
# SCRIPT_PATH=

apps/api/Dockerfile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ COPY --from=api-builder /out/vercount-api /app/vercount-api
4040
COPY --from=web-builder /src/apps/web/public/js/client.min.js /app/public/js/client.min.js
4141

4242
ENV PORT=8080
43-
ENV SCRIPT_PATH=/app/public/js/client.min.js
4443

4544
EXPOSE 8080
4645

apps/api/README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Copy `.env.example` to `.env` and set:
1515

1616
- `REDIS_URL` - direct Redis connection URL for the existing counter backend
1717
- `PORT` - HTTP port (default `8080`)
18-
- `SCRIPT_PATH` - path to the built browser script (default `../web/public/js/client.min.js`)
18+
- `SCRIPT_PATH` - optional override for the browser script path used for `/js`
1919
- `DEBUG` - set to `true` for debug logs
2020

2121
## Run
@@ -44,7 +44,8 @@ Build the local API image from the repo root:
4444
pnpm api:docker:build
4545
```
4646

47-
The image build includes the built browser script for `/js`, so the runtime container does not depend on a host-local `apps/web/public/js/client.min.js` path.
47+
The image build includes the built browser script for `/js`, and the API uses that bundled copy automatically inside the container.
48+
`SCRIPT_PATH` remains available as an override if you ever need to point at a different file.
4849

4950
## Docker Compose
5051

@@ -57,6 +58,7 @@ pnpm api:compose
5758
```
5859

5960
This uses `compose.yaml`, starts the published GHCR image from the repository root, and keeps using your existing Redis backend.
61+
If you need to override the bundled `/js` file path for a one-off run, set `SCRIPT_PATH` in the shell before starting Compose.
6062

6163
The production-like Compose file uses:
6264

@@ -73,6 +75,7 @@ pnpm api:compose:local
7375
```
7476

7577
This uses `compose-local.yaml`, builds the API image locally, and wires the API container to `redis://redis:6379/0`.
78+
It also defaults to the bundled in-image `/js` asset, with `SCRIPT_PATH` still available as a one-off shell override.
7679

7780
Stop the production-like Compose workflow from the repo root with:
7881

apps/api/internal/app/config.go

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ import (
66
"strings"
77
)
88

9+
const (
10+
containerScriptPath = "/app/public/js/client.min.js"
11+
localScriptPath = "../web/public/js/client.min.js"
12+
)
13+
914
type Config struct {
1015
Addr string
1116
RedisURL string
@@ -29,10 +34,7 @@ func LoadConfig() (Config, error) {
2934
return Config{}, fmt.Errorf("REDIS_URL is required")
3035
}
3136

32-
scriptPath := strings.TrimSpace(os.Getenv("SCRIPT_PATH"))
33-
if scriptPath == "" {
34-
scriptPath = "../web/public/js/client.min.js"
35-
}
37+
scriptPath := resolveScriptPath()
3638

3739
debug := strings.EqualFold(strings.TrimSpace(os.Getenv("DEBUG")), "true")
3840

@@ -77,3 +79,15 @@ func LoadEnvFile(path string) error {
7779

7880
return nil
7981
}
82+
83+
func resolveScriptPath() string {
84+
if override := strings.TrimSpace(os.Getenv("SCRIPT_PATH")); override != "" {
85+
return override
86+
}
87+
88+
if _, err := os.Stat(containerScriptPath); err == nil {
89+
return containerScriptPath
90+
}
91+
92+
return localScriptPath
93+
}

compose-local.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ services:
77
environment:
88
PORT: ${API_PORT:-8080}
99
REDIS_URL: redis://redis:6379/0
10-
SCRIPT_PATH: /app/public/js/client.min.js
10+
SCRIPT_PATH: ${SCRIPT_PATH:-}
1111
DEBUG: ${DEBUG:-false}
1212
depends_on:
1313
- redis

compose.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ services:
55
- ./apps/api/.env
66
environment:
77
PORT: ${API_PORT:-8080}
8-
SCRIPT_PATH: /app/public/js/client.min.js
8+
SCRIPT_PATH: ${SCRIPT_PATH:-}
99
ports:
1010
- "${API_PORT:-8080}:8080"
1111
restart: unless-stopped

0 commit comments

Comments
 (0)