mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-01 08:53:13 +00:00
refactor(server): inject the transit base URL and the kitinerary paths as config tokens
The ownership rule says a boot-stable value that only Nest providers read belongs to a registerAs token, yet TransitService froze TRANSIT_API_URL in a module-top readEnv() const and KitineraryExtractorService read KITINERARY_EXTRACTOR_PATH and PATH through readEnv() in its probe. Both now come from tokens: transitConfig and kitineraryConfig, derived in boot-derive.ts and dropped from deriveIntegrations, so readEnv() no longer reads those variables at all. TransitModule and KitineraryExtractorModule import AppConfigModule, which keeps them buildable on their own in tests. Behaviour is unchanged: the same defaults, the same trailing-slash strip and PATH split, now frozen per built app instead of at import. The app-config README names each boot-stable variable that stays on readEnv() together with the reader the container cannot inject into.
This commit is contained in:
@@ -9,7 +9,7 @@
|
||||
* mutate mid-lifetime, belongs in derive.ts instead.
|
||||
*/
|
||||
import type { RawEnv } from './derive';
|
||||
import { parseBool, positiveIntOr } from './parsers';
|
||||
import { parseBool, positiveIntOr, stripTrailingSlashes } from './parsers';
|
||||
|
||||
/**
|
||||
* Longer than the upstream idle timeout of the common reverse proxies and load
|
||||
@@ -42,10 +42,32 @@ export function deriveStorage(raw: RawEnv) {
|
||||
};
|
||||
}
|
||||
|
||||
/** The Transitous/MOTIS instance TransitService proxies to. */
|
||||
export function deriveTransit(raw: RawEnv) {
|
||||
return {
|
||||
apiBase: stripTrailingSlashes(raw.TRANSIT_API_URL || 'https://api.transitous.org'),
|
||||
};
|
||||
}
|
||||
|
||||
/** Where KitineraryExtractorService looks for its binary when the module starts. */
|
||||
export function deriveKitinerary(raw: RawEnv) {
|
||||
return {
|
||||
extractorPath: raw.KITINERARY_EXTRACTOR_PATH,
|
||||
// Windows spells it Path; every other platform PATH. Split here so the
|
||||
// probe gets a list and never re-implements the delimiter.
|
||||
searchPath: (raw.PATH || raw.Path || '')
|
||||
.split(process.platform === 'win32' ? ';' : ':')
|
||||
.map((p) => p.trim())
|
||||
.filter(Boolean),
|
||||
};
|
||||
}
|
||||
|
||||
/** One entry per token: the namespace it registers under and the function it derives with. */
|
||||
export const BOOT_DERIVERS = {
|
||||
http: deriveHttpBoot,
|
||||
storage: deriveStorage,
|
||||
transit: deriveTransit,
|
||||
kitinerary: deriveKitinerary,
|
||||
} as const;
|
||||
|
||||
export type BootNamespace = keyof typeof BOOT_DERIVERS;
|
||||
|
||||
Reference in New Issue
Block a user