Skip to content

Commit 68b2ad2

Browse files
authored
feat: Allow the deployment of MFEs in subdirectories. (#113)
1 parent 701d14f commit 68b2ad2

File tree

6 files changed

+83
-73
lines changed

6 files changed

+83
-73
lines changed

src/config.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,15 @@
2424
* @module Config
2525
*/
2626

27-
import { APP_CONFIG_INITIALIZED } from './initialize';
27+
import { APP_CONFIG_INITIALIZED, CONFIG_CHANGED } from './constants';
2828
import { publish, subscribe } from './pubSub';
2929
import { ensureDefinedConfig } from './utils';
3030

31-
export const CONFIG_TOPIC = 'CONFIG';
32-
export const CONFIG_CHANGED = `${CONFIG_TOPIC}.CHANGED`;
33-
3431
const ENVIRONMENT = process.env.NODE_ENV;
3532
let config = {
3633
ACCESS_TOKEN_COOKIE_NAME: process.env.ACCESS_TOKEN_COOKIE_NAME,
3734
BASE_URL: process.env.BASE_URL,
35+
PUBLIC_PATH: process.env.PUBLIC_PATH || '/',
3836
CREDENTIALS_BASE_URL: process.env.CREDENTIALS_BASE_URL,
3937
CSRF_TOKEN_API_PATH: process.env.CSRF_TOKEN_API_PATH,
4038
DISCOVERY_API_BASE_URL: process.env.DISCOVERY_API_BASE_URL,

src/constants.js

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
2+
/** @constant */
3+
export const APP_TOPIC = 'APP';
4+
5+
export const APP_PUBSUB_INITIALIZED = `${APP_TOPIC}.PUBSUB_INITIALIZED`;
6+
7+
/**
8+
* Event published when the application initialization sequence has finished loading any dynamic
9+
* configuration setup in a custom config handler.
10+
*
11+
* @event
12+
*/
13+
export const APP_CONFIG_INITIALIZED = `${APP_TOPIC}.CONFIG_INITIALIZED`;
14+
15+
/**
16+
* Event published when the application initialization sequence has finished determining the user's
17+
* authentication state, creating an authenticated API client, and executing auth handlers.
18+
*
19+
* @event
20+
*/
21+
export const APP_AUTH_INITIALIZED = `${APP_TOPIC}.AUTH_INITIALIZED`;
22+
23+
/**
24+
* Event published when the application initialization sequence has finished initializing
25+
* internationalization and executing any i18n handlers.
26+
*
27+
* @event
28+
*/
29+
export const APP_I18N_INITIALIZED = `${APP_TOPIC}.I18N_INITIALIZED`;
30+
31+
/**
32+
* Event published when the application initialization sequence has finished initializing the
33+
* logging service and executing any logging handlers.
34+
*
35+
* @event
36+
*/
37+
export const APP_LOGGING_INITIALIZED = `${APP_TOPIC}.LOGGING_INITIALIZED`;
38+
39+
/**
40+
* Event published when the application initialization sequence has finished initializing the
41+
* analytics service and executing any analytics handlers.
42+
*
43+
* @event
44+
*/
45+
export const APP_ANALYTICS_INITIALIZED = `${APP_TOPIC}.ANALYTICS_INITIALIZED`;
46+
47+
/**
48+
* Event published when the application initialization sequence has finished. Applications should
49+
* subscribe to this event and start rendering the UI when it has fired.
50+
*
51+
* @event
52+
*/
53+
export const APP_READY = `${APP_TOPIC}.READY`;
54+
55+
/**
56+
* Event published when the application initialization sequence has aborted. This is frequently
57+
* used to show an error page when an initialization error has occurred.
58+
*
59+
* @see {@link module:React~ErrorPage}
60+
* @event
61+
*/
62+
export const APP_INIT_ERROR = `${APP_TOPIC}.INIT_ERROR`;
63+
64+
/** @constant */
65+
export const CONFIG_TOPIC = 'CONFIG';
66+
67+
export const CONFIG_CHANGED = `${CONFIG_TOPIC}.CHANGED`;
68+

src/index.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ export {
77
ensureDefinedConfig,
88
} from './utils';
99
export {
10-
initialize,
1110
APP_TOPIC,
1211
APP_PUBSUB_INITIALIZED,
1312
APP_CONFIG_INITIALIZED,
@@ -17,6 +16,11 @@ export {
1716
APP_ANALYTICS_INITIALIZED,
1817
APP_READY,
1918
APP_INIT_ERROR,
19+
CONFIG_TOPIC,
20+
CONFIG_CHANGED,
21+
} from './constants';
22+
export {
23+
initialize,
2024
history,
2125
initError,
2226
auth,
@@ -27,8 +31,6 @@ export {
2731
unsubscribe,
2832
} from './pubSub';
2933
export {
30-
CONFIG_TOPIC,
31-
CONFIG_CHANGED,
3234
getConfig,
3335
setConfig,
3436
mergeConfig,

src/initialize.js

+4-63
Original file line numberDiff line numberDiff line change
@@ -56,76 +56,17 @@ import { configure as configureLogging, getLoggingService, NewRelicLoggingServic
5656
import { configure as configureAnalytics, SegmentAnalyticsService, identifyAnonymousUser, identifyAuthenticatedUser } from './analytics';
5757
import { getAuthenticatedHttpClient, configure as configureAuth, ensureAuthenticatedUser, fetchAuthenticatedUser, hydrateAuthenticatedUser, getAuthenticatedUser, AxiosJwtAuthService } from './auth';
5858
import { configure as configureI18n } from './i18n';
59-
60-
/** @constant */
61-
export const APP_TOPIC = 'APP';
62-
63-
export const APP_PUBSUB_INITIALIZED = `${APP_TOPIC}.PUBSUB_INITIALIZED`;
64-
65-
/**
66-
* Event published when the application initialization sequence has finished loading any dynamic
67-
* configuration setup in a custom config handler.
68-
*
69-
* @event
70-
*/
71-
export const APP_CONFIG_INITIALIZED = `${APP_TOPIC}.CONFIG_INITIALIZED`;
72-
73-
/**
74-
* Event published when the application initialization sequence has finished determining the user's
75-
* authentication state, creating an authenticated API client, and executing auth handlers.
76-
*
77-
* @event
78-
*/
79-
export const APP_AUTH_INITIALIZED = `${APP_TOPIC}.AUTH_INITIALIZED`;
80-
81-
/**
82-
* Event published when the application initialization sequence has finished initializing
83-
* internationalization and executing any i18n handlers.
84-
*
85-
* @event
86-
*/
87-
export const APP_I18N_INITIALIZED = `${APP_TOPIC}.I18N_INITIALIZED`;
88-
89-
/**
90-
* Event published when the application initialization sequence has finished initializing the
91-
* logging service and executing any logging handlers.
92-
*
93-
* @event
94-
*/
95-
export const APP_LOGGING_INITIALIZED = `${APP_TOPIC}.LOGGING_INITIALIZED`;
96-
97-
/**
98-
* Event published when the application initialization sequence has finished initializing the
99-
* analytics service and executing any analytics handlers.
100-
*
101-
* @event
102-
*/
103-
export const APP_ANALYTICS_INITIALIZED = `${APP_TOPIC}.ANALYTICS_INITIALIZED`;
104-
105-
/**
106-
* Event published when the application initialization sequence has finished. Applications should
107-
* subscribe to this event and start rendering the UI when it has fired.
108-
*
109-
* @event
110-
*/
111-
export const APP_READY = `${APP_TOPIC}.READY`;
112-
113-
/**
114-
* Event published when the application initialization sequence has aborted. This is frequently
115-
* used to show an error page when an initialization error has occurred.
116-
*
117-
* @see {@link module:React~ErrorPage}
118-
* @event
119-
*/
120-
export const APP_INIT_ERROR = `${APP_TOPIC}.INIT_ERROR`;
59+
import { APP_PUBSUB_INITIALIZED, APP_CONFIG_INITIALIZED, APP_AUTH_INITIALIZED, APP_I18N_INITIALIZED, APP_LOGGING_INITIALIZED, APP_ANALYTICS_INITIALIZED, APP_READY, APP_INIT_ERROR } from './constants';
12160

12261
/**
12362
* A browser history object created by the [history](https://github.com/ReactTraining/history)
12463
* package. Applications are encouraged to use this history object, rather than creating their own,
12564
* as behavior may be undefined when managing history via multiple mechanisms/instances.
12665
*
12766
*/
128-
export const history = createBrowserHistory();
67+
export const history = createBrowserHistory({
68+
basename: getConfig().PUBLIC_PATH,
69+
});
12970

13071
/**
13172
* The default handler for the initialization lifecycle's `initError` phase. Logs the error to the

src/initialize.test.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ import {
77
APP_ANALYTICS_INITIALIZED,
88
APP_I18N_INITIALIZED,
99
APP_READY,
10-
initialize,
1110
APP_INIT_ERROR,
12-
} from './initialize';
11+
} from './constants';
12+
import { initialize } from './initialize';
1313
import { subscribe } from './pubSub';
1414

1515
import { configure as configureLogging, NewRelicLoggingService, getLoggingService, logError } from './logging';

src/react/AppProvider.jsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ import ErrorBoundary from './ErrorBoundary';
88
import AppContext from './AppContext';
99
import { useAppEvent } from './hooks';
1010
import { getAuthenticatedUser, AUTHENTICATED_USER_CHANGED } from '../auth';
11-
import { getConfig, CONFIG_CHANGED } from '../config';
11+
import { getConfig } from '../config';
12+
import { CONFIG_CHANGED } from '../constants';
1213
import { history } from '../initialize';
1314
import { getLocale, getMessages, IntlProvider, LOCALE_CHANGED } from '../i18n';
1415

0 commit comments

Comments
 (0)