Skip to content
This repository was archived by the owner on Mar 13, 2025. It is now read-only.

Commit 84c5000

Browse files
Merge pull request #82 from topcoder-platform/PROD-1531_update_documentation
Prod 1531 update documentation
2 parents e154b57 + a122da3 commit 84c5000

File tree

4 files changed

+116
-23
lines changed

4 files changed

+116
-23
lines changed

README.md

Lines changed: 92 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,95 @@
11
# Topcoder Frame Single-Spa Application (mfe-core)
22

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.
55

66
## Overview
77

88
Topcoder Single Spa consist of 3 main components:
99

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.
1212
- Any other micro application can be loaded as main content of the overall application.
1313

1414
## Requirements
1515

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
2265

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
2493

2594
This `mfe-core` app has 2 types of configs:
2695

@@ -62,27 +131,28 @@ This `mfe-core` app has 2 types of configs:
62131
| Command | Description |
63132
| -------------------- | ---------------------- |
64133
| `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) |
65136
| `npm run build` | Build app with webpack and puts files to the `dist` folder |
66137
| `npm run local-server` | Run the server on local machine with nodemon |
67138
| `npm run local-client` | Run the frontend on local machine with webpack-dev-server |
68139
| `npm run lint` | Check code for lint errors |
69140
| `npm run format` | Format code using prettier |
70141
| `npm run test` | Run unit tests |
71142

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)
73144

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`:
75146

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+
```
84151
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+
```
86156
87157
## Local Deployment from web server (node)
88158

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
"name": "@topcoder/mfe-core",
33
"scripts": {
44
"start": "node server.js",
5+
"start-server": "sh start-server.sh",
6+
"start-client": "sh start-client.sh",
57
"build": "webpack --mode=${APPMODE:-development} --env.APPENV=${APPENV:-dev} --env.SEGMENT_ANALYTICS_KEY=${SEGMENT_ANALYTICS_KEY:-NS}",
68
"local-server": "nodemon ./server.js",
79
"local-client": "webpack-dev-server --mode=development --port 8080 --env.APPENV=local",
@@ -45,4 +47,4 @@
4547
"single-spa-layout": "1.0.0-beta.12",
4648
"nodemon": "^2.0.6"
4749
}
48-
}
50+
}

start-client.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/bin/bash
2+
#Load nvm
3+
export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")"
4+
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
5+
6+
export APPMODE="development"
7+
export APPENV="local-multi"
8+
9+
nvm use
10+
npm run local-client

start-server.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/bash
2+
#Load nvm
3+
export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")"
4+
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
5+
6+
export APPMODE="development"
7+
export APPENV="local-multi"
8+
9+
nvm use
10+
npm i
11+
npm run local-server

0 commit comments

Comments
 (0)