Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/how_tos/migrate-frontend-app.md
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,7 @@ Other configuration is now optional, and many values have been given sensible de

- environment: EnvironmentTypes
- basename: string
- mfeConfigApiUrl: string | null
- runtimeConfigJsonUrl: string | null
- accessTokenCookieName: string
- languagePreferenceCookieName: string
- userInfoCookieName: string
Expand Down
4 changes: 2 additions & 2 deletions runtime/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
*
* https://github.com/openedx/edx-platform/blob/master/lms/djangoapps/mfe_config_api/docs/decisions/0001-mfe-config-api.rst
*
* The runtime configuration method can be enabled by supplying a mfeConfigApiUrl via one of the other
* The runtime configuration method can be enabled by supplying a runtimeConfigJsonUrl via one of the other
* two configuration methods above.
*
* Runtime configuration is particularly useful if you need to supply different configurations to
Expand Down Expand Up @@ -123,7 +123,7 @@ let siteConfig: SiteConfig = {
apps: [],
externalRoutes: [],
externalLinkUrlOverrides: [],
mfeConfigApiUrl: null,
runtimeConfigJsonUrl: null,
theme: {},
accessTokenCookieName: 'edx-jwt-cookie-header-payload',
csrfTokenApiPath: '/csrf/api/v1/token',
Expand Down
17 changes: 11 additions & 6 deletions runtime/initialize.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ import {
} from './logging';
import { GoogleAnalyticsLoader } from './scripts';
import { publish } from './subscriptions';
import { EnvironmentTypes } from '../types';

/**
* If set in configuration, a basename will be prepended to all relative routes under BrowserRouter.
Expand Down Expand Up @@ -165,17 +166,21 @@ async function fileConfig() {
*/
async function runtimeConfig() {
try {
const { mfeConfigApiUrl, siteId } = getSiteConfig();
const { runtimeConfigJsonUrl, environment } = getSiteConfig();
Comment on lines -168 to +169
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My understanding of the new runtime config architecture is that the build-time site config will just point to a URL, and we won't have a concept of siteId.


if (mfeConfigApiUrl) {
if (runtimeConfigJsonUrl) {
const apiConfig = { headers: { accept: 'application/json' } };
const apiService = await configureCache();

const params = new URLSearchParams();
params.append('mfe', siteId);
const url = `${mfeConfigApiUrl}?${params.toString()}`;
const runtimeConfigUrl = new URL(runtimeConfigJsonUrl);

const { data } = await apiService.get(url, apiConfig);
// In development mode, add a timestamp as a cache buster
// to support live-editing runtime config JSON
if (environment === EnvironmentTypes.DEVELOPMENT) {
runtimeConfigUrl.searchParams.set('timestamp', Date.now());
}
Comment on lines +177 to +181
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is super helpful for local dev (live editing the json and seeing things update). I'm not sure if this is a pattern we're happy with, and I'm very open to other ideas about how to handle this use case.


const { data } = await apiService.get(runtimeConfigUrl.toString(), apiConfig);
mergeSiteConfig(data);
}
} catch (error) {
Expand Down
4 changes: 2 additions & 2 deletions runtime/initialize.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ describe('initialize', () => {
handlers: {
config: () => {
mergeSiteConfig({
mfeConfigApiUrl: 'http://localhost:18000/api/mfe/v1/config',
runtimeConfigJsonUrl: 'http://localhost:18000/api/mfe/v1/config',
siteId: 'auth',
});
}
Expand Down Expand Up @@ -324,7 +324,7 @@ describe('initialize', () => {
handlers: {
config: () => {
mergeSiteConfig({
mfeConfigApiUrl: 'http://localhost:18000/api/mfe/v1/config',
runtimeConfigJsonUrl: 'http://localhost:18000/api/mfe/v1/config',
siteId: 'auth',
});
}
Expand Down
2 changes: 1 addition & 1 deletion shell/site.config.dev.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const siteConfig: SiteConfig = {

// API URLs
lmsBaseUrl: 'http://local.openedx.io:8000',
mfeConfigApiUrl: 'http://apps.local.openedx.io:8080/api/mfe_config/v1',
runtimeConfigJsonUrl: 'http://apps.local.openedx.io:8080/api/mfe_config/v1',
};

export default siteConfig;
2 changes: 1 addition & 1 deletion test-site/site.config.build.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const siteConfig: SiteConfig = {
logoutUrl: 'http://local.openedx.io:8000/logout',

environment: EnvironmentTypes.PRODUCTION,
mfeConfigApiUrl: 'http://apps.local.openedx.io:8080/api/mfe_config/v1',
runtimeConfigJsonUrl: 'http://apps.local.openedx.io:8080/api/mfe_config/v1',
apps: [
shellApp,
headerApp,
Expand Down
2 changes: 1 addition & 1 deletion test-site/site.config.dev.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const siteConfig: SiteConfig = {
logoutUrl: 'http://local.openedx.io:8000/logout',

environment: EnvironmentTypes.DEVELOPMENT,
mfeConfigApiUrl: 'http://apps.local.openedx.io:8080/api/mfe_config/v1',
runtimeConfigJsonUrl: 'http://apps.local.openedx.io:8080/api/mfe_config/v1',
apps: [
shellApp,
headerApp,
Expand Down
2 changes: 1 addition & 1 deletion types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export interface OptionalSiteConfig {
basename: string,
externalRoutes: ExternalRoute[],
externalLinkUrlOverrides: string[],
mfeConfigApiUrl: string | null,
runtimeConfigJsonUrl: string | null,

// Theme
theme: Theme,
Expand Down
Loading