Skip to content

Commit 9e30e8c

Browse files
fix: Solving PageRoute import and other issues on example app (#3956)
* fix: solving pageroute import issue on example app * fix: lint * revert: restoring package-lock and reverting frontend platform upgrade * chore: comments addressed * docs: updating example app running instructions
1 parent 049f967 commit 9e30e8c

File tree

4 files changed

+46
-19
lines changed

4 files changed

+46
-19
lines changed

README.md

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -514,10 +514,34 @@ Paragon components can have different behavior in the MFE environment. `example`
514514

515515
Steps to install the `example` app.
516516

517+
To set up the example app with a local Tutor installation, you'll need to configure a Tutor plugin to handle CORS settings
518+
519+
Prerequisites.
520+
521+
Before running the example app, ensure you have a local Tutor installation configured.
522+
1. Create a new file (i.e. `paragon-example-app.py`) in your tutor plugins folder (`tutor plugins printroot` to get the path).
523+
2. Add the following content to the paragon-example-app.py file:
524+
```
525+
from tutor import hooks
526+
527+
hooks.Filters.ENV_PATCHES.add_item(
528+
(
529+
"openedx-lms-development-settings",
530+
"""
531+
CORS_ORIGIN_WHITELIST.append("http://localhost:8080")
532+
LOGIN_REDIRECT_WHITELIST.append("http://localhost:8080")
533+
CSRF_TRUSTED_ORIGINS.append("http://localhost:8080")
534+
"""
535+
)
536+
)
537+
```
538+
3. Enable the plugin: `tutor plugins enable paragon-example-app`
539+
4. Apply configuration changes: `tutor config save` && `tutor dev restart`
540+
541+
Running the Example App:
517542
1. `npm install` to install dependencies.
518-
2. Launch any devstack. It is required for MFE to login into the system and set up configs.
519-
3. `npm run start-example-mfe` to start the app.
520-
4. Go to the `example/src/MyComponent.jsx` and use Paragon components inside the MFE environment.
543+
2. `npm run example:start` to start the app.
544+
3. Go to the `example/src/MyComponent.jsx` and use Paragon components inside the MFE environment.
521545

522546
## Semantic Release
523547

example/.env.development

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
NODE_ENV='development'
2-
REFRESH_ACCESS_TOKEN_ENDPOINT='http://localhost:18000/login_refresh'
3-
LMS_BASE_URL='http://localhost:18000'
4-
ACCESS_TOKEN_COOKIE_NAME='edx-jwt-cookie-header-payload'
1+
NODE_ENV=development
2+
REFRESH_ACCESS_TOKEN_ENDPOINT=http://local.openedx.io:8000/login_refresh
3+
LMS_BASE_URL=http://local.openedx.io:8000
4+
ACCESS_TOKEN_COOKIE_NAME=edx-jwt-cookie-header-payload
5+
BASE_URL=http://local.openedx.io:8080
6+
LOGIN_URL=http://local.openedx.io:8000/login
7+
LOGOUT_URL=http://local.openedx.io:8000/logout
8+
CSRF_TOKEN_API_PATH=/csrf/api/v1/token

example/public/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<!doctype html>
22
<html lang="en-us">
33
<head>
4-
<title>Example</title>
4+
<title>Paragon Example</title>
55
<meta charset="utf-8">
66
<meta name="viewport" content="width=device-width, initial-scale=1.0">
77
</head>

example/src/index.jsx

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,30 @@
1-
import React from 'react';
2-
import ReactDOM from 'react-dom';
1+
import { createRoot } from 'react-dom/client';
32
import {
43
AppProvider,
54
ErrorPage,
6-
PageRoute,
5+
PageWrap,
76
} from '@edx/frontend-platform/react';
87
import { APP_INIT_ERROR, APP_READY, initialize } from '@edx/frontend-platform';
98
import { subscribe } from '@edx/frontend-platform/pubSub';
109
import MyComponent from './MyComponent';
1110

1211
import './index.scss';
1312

13+
const container = document.getElementById('root');
14+
const root = createRoot(container);
15+
1416
subscribe(APP_READY, () => {
15-
ReactDOM.render(
17+
root.render(
1618
<AppProvider>
17-
<PageRoute
18-
exact
19-
path="/"
20-
component={MyComponent}
21-
/>
19+
<PageWrap>
20+
<MyComponent />
21+
</PageWrap>
2222
</AppProvider>,
23-
document.getElementById('root'),
2423
);
2524
});
2625

2726
subscribe(APP_INIT_ERROR, (error) => {
28-
ReactDOM.render(<ErrorPage message={error.message} />, document.getElementById('root'));
27+
root.render(<ErrorPage message={error.message} />);
2928
});
3029

3130
initialize({

0 commit comments

Comments
 (0)