|
1 |
| -# taas-admin-app |
2 |
| -taas-admin-app for managing taas administrative activities |
| 1 | +# Topcoder TaaS Admin Micro-app |
| 2 | + |
| 3 | +This is a [single-spa](https://single-spa.js.org/) example React microapp. |
| 4 | + |
| 5 | +> NOTE. This application have been configured to be run as child app of a single-spa application. So while this app can be deployed and run independently, we would need some frame [single-spa](https://single-spa.js.org/) which would load it. While technically we can achieve running this app as standalone app it's strongly not recommended by the author of the `single-spa` approach, see this [GitHub Issue](https://github.com/single-spa/single-spa/issues/640) for details. |
| 6 | +
|
| 7 | +## Requirements |
| 8 | + |
| 9 | +- node - v10.22.1 |
| 10 | +- npm - v6.14.6 |
| 11 | + |
| 12 | +## Technology Stack |
| 13 | + |
| 14 | +- React 16.12 |
| 15 | +- Router via [Reach Router](https://reach.tech/router/) |
| 16 | +- CSS Modules with SCSS |
| 17 | +- [React Inline SVG](https://github.com/airbnb/babel-plugin-inline-react-svg) |
| 18 | +- We use **Redux Store** for storing page data if we need to edit it. Otherwise we can use local state. |
| 19 | +- [react-redux-toastr](https://www.npmjs.com/package/react-redux-toastr) for success/error popups in the bottom left corner. |
| 20 | + |
| 21 | +## Config |
| 22 | + |
| 23 | +For available variables config which depend on the running environment (`APPENV=dev` or `APPENV=prod`), please refer to `config/development.js` and `config/production.js`. |
| 24 | + |
| 25 | +For application constants which don't depend on the running environment use `src/constants/index.js`. |
| 26 | + |
| 27 | +## NPM Commands |
| 28 | + |
| 29 | +| Command | Description | |
| 30 | +| --------------------- | ----------------------------------------------------------------- | |
| 31 | +| `npm start` | Run server which serves production ready build from `dist` folder | |
| 32 | +| `npm run dev` | Run app in the development mode | |
| 33 | +| `npm run dev-https` | Run app in the development mode using HTTPS protocol | |
| 34 | +| `npm run build` | Build app for production and puts files to the `dist` folder | |
| 35 | +| `npm run analyze` | Analyze dependencies sizes and opens report in the browser | |
| 36 | +| `npm run lint` | Check code for lint errors | |
| 37 | +| `npm run format` | Format code using prettier | |
| 38 | +| `npm run test` | Run unit tests | |
| 39 | +| `npm run watch-tests` | Watch for file changes and run unit tests on changes | |
| 40 | +| `npm run coverage` | Generate test code coverage report | |
| 41 | + |
| 42 | +## Deployment to Production |
| 43 | + |
| 44 | +- `npm i` - install dependencies |
| 45 | +- `npm build` - build code to `dist/` folder |
| 46 | +- Now you can host `dist/` folder using any static server. For example, you may run a simple `Express` server by running `npm start`. |
| 47 | + |
| 48 | +### Deploying to Heroku |
| 49 | + |
| 50 | +Make sure you have [Heroku CLI](https://devcenter.heroku.com/articles/heroku-cli) installed and you have a Heroku account. And then inside the project folder run the next commands: |
| 51 | + |
| 52 | +- If there is not Git repository initiated yet, create a repo and commit all the files: |
| 53 | + - `git init` |
| 54 | + - `git add .` |
| 55 | + - `git commit -m 'initial commit'` |
| 56 | +- `heroku apps:create` - create Heroku app |
| 57 | +- `git push heroku master` - push changes to Heroku and trigger deploying |
| 58 | +- Now you have to configure frame app to use the URL provided by Heroku like `https://<APP-NAME>.herokuapp.com/topcoder-micro-frontends-teams.js` to load this micro-app. |
| 59 | + |
| 60 | +## How to run Locally for Development |
| 61 | + |
| 62 | +TaaS App is done using Single SPA micro-frontend architecture https://single-spa.js.org/. So to start it, we would also have to run Frame App and Navbar App. Here I would show the steps to run locally everything we need. |
| 63 | + |
| 64 | +### Local Authentication |
| 65 | + |
| 66 | +First of all, to authenticate locally we have to run a local authentication service. |
| 67 | + |
| 68 | +- Clone this repository into `taas-admin-app`. |
| 69 | +- Inside the folder `taas-admin-app/local/auth-local` run `npm start`. |
| 70 | +- You would need npm 5+ for it. This would start a local sever on port 5000 which could be used for local Authentication. |
| 71 | + |
| 72 | +### Local Domain |
| 73 | + |
| 74 | +Some config files are using domain `local.topcoder-dev.com`. You can change it to `localhost` in all the configs of each repo mentioned below. Or on your local machine, update file `/etc/hosts` add the line `127.0.0.1 local.topcoder-dev.com`. This file has another path on Windows. |
| 75 | + |
| 76 | +### Run Applications |
| 77 | + |
| 78 | +1. Run **Frame** App: |
| 79 | + |
| 80 | + ```sh |
| 81 | + git clone https://github.com/topcoder-platform/micro-frontends-frame.git |
| 82 | + cd micro-frontends-frame |
| 83 | + # inside folder "micro-frontends-frame" run: |
| 84 | + |
| 85 | + nvm use # or make sure to use Node 10 |
| 86 | + npm i # to install dependencies |
| 87 | + |
| 88 | + # set environment variables: |
| 89 | + |
| 90 | + export APPMODE="development" |
| 91 | + export APPENV="local-multi" |
| 92 | + |
| 93 | + npm run local-server |
| 94 | + |
| 95 | + # this would start frame server on http://localhost:3000 |
| 96 | + ``` |
| 97 | + |
| 98 | + open one more terminal window in the same folder and run: |
| 99 | + |
| 100 | + ```sh |
| 101 | + # set environment variables: |
| 102 | + |
| 103 | + export APPMODE="development" |
| 104 | + export APPENV="local-multi" |
| 105 | + |
| 106 | + npm run local-client |
| 107 | + |
| 108 | + # this host frame client code on http://localhost:8080 |
| 109 | + ``` |
| 110 | + |
| 111 | +2. Run **Navbar** micro-app: |
| 112 | + |
| 113 | + ```sh |
| 114 | + git clone https://github.com/topcoder-platform/micro-frontends-navbar-app.git |
| 115 | + cd micro-frontends-navbar-app |
| 116 | + ``` |
| 117 | + |
| 118 | + Update in file `micro-frontends-navbar-app/blob/dev/config/dev.js` values for `ACCOUNTS_APP_CONNECTOR` and `AUTH` to `http://localhost:5000` so Navbar app which handles authentication uses our local Authentication service. |
| 119 | + |
| 120 | + ```sh |
| 121 | + # inside folder "micro-frontends-navbar-app" run: |
| 122 | + |
| 123 | + nvm use # or make sure to use Node 10 |
| 124 | + npm i # to install dependencies |
| 125 | + |
| 126 | + npm run dev |
| 127 | + |
| 128 | + # this host navbar app as http://localhost:3001/navbar/topcoder-micro-frontends-navbar-app.js |
| 129 | + ``` |
| 130 | + |
| 131 | +3. Run **TaaS** micro-app: |
| 132 | + |
| 133 | + ```sh |
| 134 | + # inside folder "taas-app" run: |
| 135 | + |
| 136 | + nvm use # or make sure to use Node 10 |
| 137 | + npm i # to install dependencies |
| 138 | + |
| 139 | + npm run dev |
| 140 | + |
| 141 | + # this host TaaS App as http://localhost:8501/taas-app/topcoder-micro-frontends-teams.js |
| 142 | + ``` |
| 143 | + |
| 144 | +4. Now we have to update the `micro-frontends-frame` app to show our local version of TaaS App, instead of remote one. Update file `micro-frontends-frame/config/micro-frontends-config-local.json`: |
| 145 | + |
| 146 | + ```js |
| 147 | + // replace line |
| 148 | + "@topcoder/micro-frontends-teams": "https://platform.topcoder-dev.com/taas-app/topcoder-micro-frontends-teams.js", |
| 149 | + |
| 150 | + // with line: |
| 151 | + "@topcoder/micro-frontends-teams": "http://localhost:8501/taas-app/topcoder-micro-frontends-teams.js", |
| 152 | + ``` |
| 153 | + |
| 154 | +- Now open in the browser http://localhost:8080/taas/myteams. |
| 155 | +- If you are not logged-in yet, you should be redirected to the login page. |
| 156 | +- If you cannot see the application and redirect doesn't happen, make sure that file "http://local.topcoder-dev.com:8501/taas-app/topcoder-micro-frontends-teams.js" is loaded successfully in the Network tab. |
| 157 | + |
| 158 | +Congratulations, you successfully run the project. If you had some issue, please, try to go through README of https://github.com/topcoder-platform/micro-frontends-frame and https://github.com/topcoder-platform/micro-frontends-navbar-app. |
0 commit comments