|
1 | 1 | # Topcoder Frame Single-Spa Application (mfe-core)
|
2 | 2 |
|
3 |
| -This is the mfe-core [single-spa](https://single-spa.js.org/) application which loads all other Topcoder micro applications. |
4 |
| -It always loads **Topcoder Navbar Microapp** which show the top navigation and handles authorization and loads other microapps depend on the current URL. |
| 3 | +This is the mfe-core [single-spa](https://single-spa.js.org/) application which loads all other Topcoder micro-frontend (MFE) applications. |
| 4 | +It always loads the **Topcoder Header Microapp** which provides the top-level navigation, handles authorization, and loads other microapps depending on the current URL. |
5 | 5 |
|
6 | 6 | ## Overview
|
7 | 7 |
|
8 | 8 | Topcoder Single Spa consist of 3 main components:
|
9 | 9 |
|
10 |
| -- This frame application which is `mfe-core` [single-spa](https://single-spa.js.org/) application. The only function of this application is to register other micro applications to load. |
11 |
| -- **Topcoder Navbar Microapp** - micro application which is always loaded by the frame application and shows top navigation bar and handles user authorization. |
| 10 | +- This frame application, `mfe-core`, which is a [single-spa](https://single-spa.js.org/) application. The only function of this application is to register other micro applications to load. |
| 11 | +- **Topcoder Header Microapp** - micro application which is always loaded by the frame application and shows the top-level navigation bar and handles user authorization. |
12 | 12 | - Any other micro application can be loaded as main content of the overall application.
|
13 | 13 |
|
14 | 14 | ## Requirements
|
15 | 15 |
|
16 |
| -| Command | Versions | |
17 |
| -| -------------------- | ---------------------- | |
18 |
| -| `$ npm -v` | 6.14.6 | |
19 |
| -| `$ node -v` | 0.33.11 | |
20 |
| -| `$ nvm --version` | 0.33.11 | |
21 |
| -| `$ nvm current` | v10.22.1 | |
| 16 | +Use the node version manager [nvm](https://github.com/nvm-sh/nvm/blob/master/README.md) to easily and safely manage the required version of NodeJS (aka, node). Download and install it per the instructions for your development operating system. Installing a version of node via `nvm` will also install `npm`. |
| 17 | + |
| 18 | +Once nvm is installed, run: |
| 19 | +``` |
| 20 | +$ nvm install <insert node version> |
| 21 | +``` |
| 22 | + |
| 23 | +>Note: the node version required at the time of this writing is `10.22.1` |
| 24 | +
|
| 25 | +At the root of the project directory you'll notice a file called `.nvmrc` which specifies the node version used by the project. The command `nvm use` will use the version specified in the file if no version is supplied on the command line. |
| 26 | +See [the nvm Github README](https://github.com/nvm-sh/nvm/blob/master/README.md#nvmrc) for more information on setting this up. |
| 27 | + |
| 28 | +You can verify the versions of `nvm`, `node`, and `npm` using the commands below. |
| 29 | +| Command | Version | |
| 30 | +| ----------------- | -------- | |
| 31 | +| `$ npm -v` | 6.14.12 | |
| 32 | +| `$ node -v` | v10.22.1 | |
| 33 | +| `$ nvm --version` | 0.39.1 | |
| 34 | +| `$ nvm current` | v10.22.1 | |
| 35 | + |
| 36 | +## Local Development Setup |
| 37 | + |
| 38 | +### IDE |
| 39 | + |
| 40 | +Use the [VS Code](https://code.visualstudio.com/download) IDE for MFE development. |
| 41 | + |
| 42 | +### Hosting |
| 43 | +You will need to add the following line to your hosts file. The hosts file is normally located at `/etc/hosts` (Mac). Do not overwrite the existing localhost entry also pointing to 127.0.0.1 |
| 44 | + |
| 45 | +``` |
| 46 | +127.0.0.1 local.topcoder-dev.com |
| 47 | +``` |
| 48 | + |
| 49 | +The MFE can run in a non-ssl environment, but auth0 will complain and throw errors. In order to bypass this, you will need to install [local-ssl-proxy](https://www.npmjs.com/package/local-ssl-proxy) to run the site in ssl. The following command will install it globally: |
| 50 | +``` |
| 51 | +$ npm i -g local-ssl-proxy |
| 52 | +``` |
| 53 | + |
| 54 | +### Terminal Configuration |
| 55 | + |
| 56 | +The MFE Core Frame needs to run separate local server and client processes, each one in a separate terminal session. The navbar also needs to run its server in a terminal, along with the `local-ssl-proxy` server that will allow you to use *https* endpoints locally. Finally, each of the other micro front-end applications you want to run will also each run in their own terminal session. |
| 57 | + |
| 58 | +When developing one of the micro front-end applications you will therefore have 5 terminal sessions running at the same time: |
| 59 | + |
| 60 | +- `mfe-core` server |
| 61 | +- `mfe-core` client |
| 62 | +- `mfe-header` application |
| 63 | +- `local-ssl-proxy` server |
| 64 | +- the MFE app you're developing |
22 | 65 |
|
23 |
| -## Config |
| 66 | +Given this complexity, it is recommended that you use a tool like [iTerm2](https://iterm2.com) (on Mac) or an equivalent terminal shell on Windows to make terminal management simpler. iTerm2 allows you to setup a pre-defined window layout of terminal sessions, including the directory in which the session starts. This setup, along with simple shell scripts in each project that configure and start the environment, will allow you to get your development environment up and running quickly and easily. |
| 67 | + |
| 68 | +### Linting |
| 69 | +We use linting to enforce standardization. Please make sure all lint rules pass before creating PRs. |
| 70 | + |
| 71 | +Use the following command to check for lint errors: |
| 72 | +``` |
| 73 | +$ npm run lint |
| 74 | +``` |
| 75 | + |
| 76 | +## Git |
| 77 | +### Branching |
| 78 | +When working on Jira tickets, we link associated Git PRs and branches to the tickets. Use the following naming convention for branches: |
| 79 | + |
| 80 | +`[TICKET #]_short-description` |
| 81 | + |
| 82 | +e.g.: `PROD-1516_work-issue` |
| 83 | + |
| 84 | +### Commits |
| 85 | +We use [Smart Commits](https://bigbrassband.com/git-integration-for-jira/documentation/smart-commits.html#bbb-nav-basic-examples) to link comments and time tracking to tickets. You would enter the following as your commit message: |
| 86 | + |
| 87 | +`[TICKET #] #comment <commit message> #time <jira-formatted time>` |
| 88 | + |
| 89 | +e.g.: `PLAT-001 #comment adding readme notes #time 45m` |
| 90 | + |
| 91 | + |
| 92 | +## Application Configuration |
24 | 93 |
|
25 | 94 | This `mfe-core` app has 2 types of configs:
|
26 | 95 |
|
@@ -62,27 +131,28 @@ This `mfe-core` app has 2 types of configs:
|
62 | 131 | | Command | Description |
|
63 | 132 | | -------------------- | ---------------------- |
|
64 | 133 | | `npm start` | Run server which serves production ready build from `dist` folder |
|
| 134 | +| `npm run start-server` | Run server locally for local development (calls on local-server npm script) | |
| 135 | +| `npm run start-client` | Run client locally for local development (calls on local-client npm script) | |
65 | 136 | | `npm run build` | Build app with webpack and puts files to the `dist` folder |
|
66 | 137 | | `npm run local-server` | Run the server on local machine with nodemon |
|
67 | 138 | | `npm run local-client` | Run the frontend on local machine with webpack-dev-server |
|
68 | 139 | | `npm run lint` | Check code for lint errors |
|
69 | 140 | | `npm run format` | Format code using prettier |
|
70 | 141 | | `npm run test` | Run unit tests |
|
71 | 142 |
|
72 |
| -## Local Deployment from multi web servers (nodemon & webpack-dev-server) for local development |
| 143 | +## Local Deployment from multi web servers (nodemon & webpack-dev-server) for local development - (most common) |
73 | 144 |
|
74 |
| -To deploy `mfe-core` app locally run inside the project root `./mfe-core`: |
| 145 | +To run the `mfe-core` app locally, run the following commands from the project root `./mfe-core`: |
75 | 146 |
|
76 |
| -| Command | Description | |
77 |
| -| -------------------- | ---------------------- | |
78 |
| -| `$ export APPMODE="development"; export APPENV="local-multi"` | to add environment variables for application building on local | |
79 |
| -| `$ nvm use 10.22.1` | configure the required node and npm versions via nvm | |
80 |
| -| `$ npm i` | to install dependencies | |
81 |
| -| `$ npm run local-server` | to start the app on port `3000` | |
82 |
| -| `$ export APPMODE="development"; export APPENV="local-multi"; nvm use 10.22.1; npm i; npm run local-client` | to start the app on port `8080` (`run in another terminal`) | |
83 |
| -| `http://local.topcoder-dev.com:8080/micro-frontends-react-route` | open url in browser to access the micro frame with react micro app and micro navbar app | |
| 147 | +Terminal 1 |
| 148 | +``` |
| 149 | +$ npm run start-server |
| 150 | +``` |
84 | 151 |
|
85 |
| -⚠️ **NOTE** : for running locally, you have to use domain `local.topcoder-dev.com` with port `8080` & `3000`. On your local machine access file `/etc/hosts` add the line `127.0.0.1 local.topcoder-dev.com` and open app by URL http://local.topcoder-dev.com:8080 |
| 152 | +Terminal 2 |
| 153 | +``` |
| 154 | +$ npm run start-client |
| 155 | +``` |
86 | 156 |
|
87 | 157 | ## Local Deployment from web server (node)
|
88 | 158 |
|
|
0 commit comments