diff --git a/README.md b/README.md index 48d21f0..81de3a8 100644 --- a/README.md +++ b/README.md @@ -128,7 +128,10 @@ To stop everything: `docker compose down` (add `-v` to wipe the database). in use` from `ng serve`): run `lsof -nP -iTCP:5432 -iTCP:9092 -iTCP:8081 -iTCP:4200 -sTCP:LISTEN` and `docker ps`. Stop the other project's container (`docker stop `; its data is kept) or process, or run Angular on 4201 (`npx ng serve --port 4201`). The backend only allows - browser origins 4200 and 4201, so other ports get a CORS 403 on login. + browser origins 4200 and 4201 (on `localhost` or `127.0.0.1`), so other ports get a CORS 403 on login. +- **`127.0.0.1:4200` does not load:** `ng serve` is set to listen on `127.0.0.1` in + `angular.json`, so both `http://localhost:4200` and `http://127.0.0.1:4200` work. An older + checkout listened only on IPv6 `::1`, where only `localhost` worked. - **Login fails or the app shows the old demo-token screen:** an old backend is still running on 8081. Stop it (Ctrl+C, or `pkill -f spring-boot:run`), start it again with the command above, and hard-refresh the browser. diff --git a/backend/src/main/resources/application.yml b/backend/src/main/resources/application.yml index 3e647ed..33c49fe 100644 --- a/backend/src/main/resources/application.yml +++ b/backend/src/main/resources/application.yml @@ -41,7 +41,7 @@ crm: ttl: ${CRM_JWT_TTL:15m} # Browser origins allowed to call /api/** cross-origin (ng serve). The k3s Ingress serves # UI and API from one origin, so production needs no CORS entry. - cors-allowed-origins: ${CRM_CORS_ALLOWED_ORIGINS:http://localhost:4200,http://localhost:4201,http://127.0.0.1:4201} + cors-allowed-origins: ${CRM_CORS_ALLOWED_ORIGINS:http://localhost:4200,http://127.0.0.1:4200,http://localhost:4201,http://127.0.0.1:4201} # Synthetic demo accounts. A blank password disables the account (no built-in default). # Supply a BCrypt hash ($2a$...) in deployed environments; plain values are hashed at boot. users: diff --git a/backend/src/test/java/com/northstar/crm/security/SecurityIT.java b/backend/src/test/java/com/northstar/crm/security/SecurityIT.java index a9bd3e3..05143d8 100644 --- a/backend/src/test/java/com/northstar/crm/security/SecurityIT.java +++ b/backend/src/test/java/com/northstar/crm/security/SecurityIT.java @@ -269,6 +269,14 @@ void corsPreflight_allowsLocalAngularOrigin_only() throws Exception { .header("Access-Control-Request-Headers", "authorization")) .andExpect(status().isOk()) .andExpect(header().string("Access-Control-Allow-Origin", "http://localhost:4200")); + mockMvc + .perform( + options("/api/v1/customers") + .header("Origin", "http://127.0.0.1:4200") + .header("Access-Control-Request-Method", "GET") + .header("Access-Control-Request-Headers", "authorization")) + .andExpect(status().isOk()) + .andExpect(header().string("Access-Control-Allow-Origin", "http://127.0.0.1:4200")); mockMvc .perform( options("/api/v1/customers") diff --git a/frontend/angular.json b/frontend/angular.json index 7ad2d8b..2056cb1 100644 --- a/frontend/angular.json +++ b/frontend/angular.json @@ -99,6 +99,9 @@ }, "serve": { "builder": "@angular-devkit/build-angular:dev-server", + "options": { + "host": "127.0.0.1" + }, "configurations": { "production": { "buildTarget": "lab50-crm-ui:build:production"