@sneat/app 0.8.0 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -20,9 +20,20 @@ export function isLocalhost() {
|
|
|
20
20
|
// export const fooEnvironmentConfig = appEnvironmentConfig({ ...prod config });
|
|
21
21
|
// and drop environment.prod.ts + the production fileReplacements entirely.
|
|
22
22
|
export function appEnvironmentConfig(prod) {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
23
|
+
if (isLocalhost()) {
|
|
24
|
+
return appSpecificConfig(emulatorEnvironmentConfig);
|
|
25
|
+
}
|
|
26
|
+
// Default authDomain to the current origin so the OAuth redirect stays
|
|
27
|
+
// same-origin / first-party. Serving an app at one domain (e.g. listus.app)
|
|
28
|
+
// while authenticating against another (listus-app.web.app) triggers a
|
|
29
|
+
// cross-domain redirect that browsers flag as a look-alike and that breaks
|
|
30
|
+
// first-party auth storage. Apps override by setting firebaseConfig.authDomain.
|
|
31
|
+
const authDomain = prod.firebaseConfig.authDomain ||
|
|
32
|
+
(typeof location !== 'undefined' ? location.hostname : undefined);
|
|
33
|
+
return {
|
|
34
|
+
...prod,
|
|
35
|
+
firebaseConfig: { ...prod.firebaseConfig, authDomain },
|
|
36
|
+
};
|
|
26
37
|
}
|
|
27
38
|
function firebaseApiKey(useEmulators, apiKey) {
|
|
28
39
|
return useEmulators ? 'emulator-does-not-need-api-key' : apiKey;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"init-helpers.js","sourceRoot":"","sources":["../../../../../libs/app/src/lib/init-helpers.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,yBAAyB,EAAE,MAAM,kCAAkC,CAAC;AAE7E,6EAA6E;AAC7E,iEAAiE;AACjE,gCAAgC;AAChC,MAAM,UAAU,WAAW;IACzB,OAAO,CACL,OAAO,QAAQ,KAAK,WAAW;QAC/B,CAAC,WAAW,EAAE,WAAW,EAAE,OAAO,EAAE,SAAS,C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,CAAC,CAAC,SAAS,CAAC,CAAC;IACpE,OAAO;QACL,GAAG,IAAI;QACP,cAAc,EAAE,EAAE,GAAG,IAAI,CAAC,cAAc,EAAE,UAAU,EAAE;KACvD,CAAC;AACJ,CAAC;AAED,SAAS,cAAc,CAAC,YAAqB,EAAE,MAAc;IAC3D,OAAO,YAAY,CAAC,CAAC,CAAC,gCAAgC,CAAC,CAAC,CAAC,MAAM,CAAC;AAClE,CAAC;AAED,MAAM,UAAU,iBAAiB,CAC/B,YAAqB,EACrB,SAAiB;IAEjB,OAAO,YAAY,CAAC,CAAC,CAAC,OAAO,GAAG,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC;AACxD,CAAC;AAED,8FAA8F;AAC9F,2CAA2C;AAC3C,uBAAuB;AACvB,kBAAkB;AAClB,2CAA2C;AAC3C,IAAI;AAEJ,4BAA4B;AAC5B,MAAM,UAAU,iBAAiB,CAC/B,SAA6B;IAG7B,IAAI,MAAM,GAAuB;QAC/B,GAAG,SAAS;QACZ,cAAc,EAAE;YACd,GAAG,SAAS,CAAC,cAAc;SAC5B;KACF,CAAC;IACF,MAAM,EAAE,cAAc,EAAE,GAAG,MAAM,CAAC;IAClC,MAAM,WAAW,GAAG,CAAC,CAAC,MAAM,CAAC,cAAc,CAAC,QAAQ,CAAC;IACrD,MAAM,SAAS,GAAG,iBAAiB,CAAC,WAAW,EAAE,cAAc,CAAC,SAAS,CAAC,CAAC;IAC3E,MAAM,GAAG;QACP,GAAG,MAAM;QACT,cAAc,EAAE;YACd,GAAG,cAAc;YACjB,MAAM,EAAE,cAAc,CAAC,WAAW,EAAE,cAAc,CAAC,MAAM,CAAC;YAC1D,SAAS,EAAE,SAAS;SACrB;KACF,CAAC;IACF,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import { IEnvironmentConfig } from '@sneat/core';\nimport { emulatorEnvironmentConfig } from '../environments/environment.base';\n\n// True only when the app is actually running on a developer machine. Used to\n// decide, at RUNTIME, whether to use the Firebase emulator — see\n// appEnvironmentConfig() below.\nexport function isLocalhost(): boolean {\n return (\n typeof location !== 'undefined' &&\n ['localhost', '127.0.0.1', '[::1]', '0.0.0.0'].includes(location.hostname)\n );\n}\n\n// Fail-safe environment selection. Use the Firebase emulator ONLY when running\n// on localhost; every deployed domain gets the production config passed in.\n//\n// Because the emulator-vs-production decision is made at runtime from the\n// hostname — NOT from a build-time `fileReplacements` swap — a mis-built or\n// mis-deployed bundle can never ship the emulator config to production. This\n// structurally eliminates the recurring \"127.0.0.1 refused to connect\" class of\n// bug: forgetting `--configuration production`, a stale `dist/`, an nx cache\n// hit, or deploying a dev build can no longer point real users at the emulator.\n//\n// Apps should define a single environment.ts:\n// export const fooEnvironmentConfig = appEnvironmentConfig({ ...prod config });\n// and drop environment.prod.ts + the production fileReplacements entirely.\nexport function appEnvironmentConfig(\n prod: IEnvironmentConfig,\n): IEnvironmentConfig {\n if (isLocalhost()) {\n return appSpecificConfig(emulatorEnvironmentConfig);\n }\n // Default authDomain to the current origin so the OAuth redirect stays\n // same-origin / first-party. Serving an app at one domain (e.g. listus.app)\n // while authenticating against another (listus-app.web.app) triggers a\n // cross-domain redirect that browsers flag as a look-alike and that breaks\n // first-party auth storage. Apps override by setting firebaseConfig.authDomain.\n const authDomain =\n prod.firebaseConfig.authDomain ||\n (typeof location !== 'undefined' ? location.hostname : undefined);\n return {\n ...prod,\n firebaseConfig: { ...prod.firebaseConfig, authDomain },\n };\n}\n\nfunction firebaseApiKey(useEmulators: boolean, apiKey: string): string {\n return useEmulators ? 'emulator-does-not-need-api-key' : apiKey;\n}\n\nexport function firebaseProjectId(\n useEmulators: boolean,\n projectId: string,\n): string {\n return useEmulators ? 'demo-' + projectId : projectId;\n}\n\n// function firebaseDatabaseURL(useEmulators: boolean, projectId: string): string | undefined{\n// \t// noinspection SpellCheckingInspection\n// \treturn useEmulators\n// \t\t? undefined :\n// \t\t`https://${projectId}.firebaseio.com`;\n// }\n\n// TODO: document why needed\nexport function appSpecificConfig(\n envConfig: IEnvironmentConfig,\n // appConfig: IAppSpecificConfig,\n): IEnvironmentConfig {\n let config: IEnvironmentConfig = {\n ...envConfig,\n firebaseConfig: {\n ...envConfig.firebaseConfig,\n },\n };\n const { firebaseConfig } = config;\n const useEmulator = !!config.firebaseConfig.emulator;\n const projectId = firebaseProjectId(useEmulator, firebaseConfig.projectId);\n config = {\n ...config,\n firebaseConfig: {\n ...firebaseConfig,\n apiKey: firebaseApiKey(useEmulator, firebaseConfig.apiKey),\n projectId: projectId,\n },\n };\n return config;\n}\n"]}
|