Skip to content

Commit e04731e

Browse files
Merge pull request #65 from NatLibFi/ekir-747-configurable-env-for-magazines
Refactor magazine URL retrieval
2 parents abfc034 + bb03f49 commit e04731e

File tree

3 files changed

+28
-7
lines changed

3 files changed

+28
-7
lines changed

README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,19 @@ The following environment variables can be set to further configure the applicat
9191

9292
- Set `AXE_TEST=true` to run the application with `react-axe` enabled (only works when `NODE_ENV` is "development").
9393
- Set `ANALYZE=true` to generate bundle analysis files inside `.next/analyze` which will show bundle sizes for server and client, as well as composition.
94+
- Set `NEXT_PUBLIC_MAGAZINES_ENV` to choose which magazines environment to use. Allowed values are `production` and `playground`.
95+
- `production` uses `https://<magazines-production-url>`.
96+
- `playground` uses `https://<magazines-playground-url>`.
97+
- If not set (or set to an invalid value), it falls back to `production` when `NODE_ENV=production`, otherwise `playground`.
98+
- Set `NEXT_PUBLIC_MAGAZINES_ORIGIN` to override the allowed origin used for magazine iframe communication. If not set, the origin is derived from the selected magazines base URL.
99+
100+
Example `.env.local` setup:
101+
102+
```
103+
NEXT_PUBLIC_MAGAZINES_ENV=playground
104+
# Optional: override iframe allowed origin
105+
# NEXT_PUBLIC_MAGAZINES_ORIGIN=https://<magazines-allowed-origin>
106+
```
94107

95108
## Manager, Registry, and Application Configurations
96109

docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
version: "2"
21
services:
32
web-patron:
43
container_name: web-patron
54
build: ./
65
environment:
76
CONFIG_FILE: /config/config.yml
87
NODE_ENV: production
8+
NEXT_PUBLIC_MAGAZINES_ENV: playground
99
volumes:
1010
- ./config:/app/config
1111
ports:

src/config/magazines.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,30 @@ const MAGAZINE_API_URLS = {
1414
playground: "https://lehdet-testing.e-kirjasto.fi/feed/catalog"
1515
} as const;
1616

17+
type MagazineEnvironment = keyof typeof MAGAZINE_READER_URLS;
18+
19+
function getMagazineEnvironment(): MagazineEnvironment {
20+
const magazinesEnv = process.env.NEXT_PUBLIC_MAGAZINES_ENV;
21+
22+
if (magazinesEnv === "production" || magazinesEnv === "playground") {
23+
return magazinesEnv;
24+
}
25+
26+
return process.env.NODE_ENV === "production" ? "production" : "playground";
27+
}
28+
1729
/**
1830
* Get the magazine reader base URL based on environment
1931
*/
2032
export function getMagazineReaderUrl(): string {
21-
return process.env.NODE_ENV === "production"
22-
? MAGAZINE_READER_URLS.production
23-
: MAGAZINE_READER_URLS.playground;
33+
return MAGAZINE_READER_URLS[getMagazineEnvironment()];
2434
}
2535

2636
/**
2737
* Get the magazine API URL based on environment
2838
*/
2939
export function getMagazineApiUrl(): string {
30-
return process.env.NODE_ENV === "production"
31-
? MAGAZINE_API_URLS.production
32-
: MAGAZINE_API_URLS.playground;
40+
return MAGAZINE_API_URLS[getMagazineEnvironment()];
3341
}
3442

3543
/**

0 commit comments

Comments
 (0)