commit | author | age
|
8a7c93
|
1 |
# Adopt-A-Pup Frontend React WebApp |
bae328
|
2 |
|
8a7c93
|
3 |
The frontend web-app is a React HTML5 application that serves as a UI for backend services. |
bae328
|
4 |
|
JR |
5 |
This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app). |
|
6 |
|
8a7c93
|
7 |
The entry point is at `src/index.tsx`. |
65919c
|
8 |
|
8a7c93
|
9 |
## Prerequisites |
65919c
|
10 |
|
8a7c93
|
11 |
Node version >= 12 |
65919c
|
12 |
|
8a7c93
|
13 |
## Dependency installation |
65919c
|
14 |
|
8a7c93
|
15 |
Before starting development, install dependencies with `npm`: |
bae328
|
16 |
|
JR |
17 |
```sh |
|
18 |
npm ci |
|
19 |
``` |
|
20 |
|
8a7c93
|
21 |
## Frontend environment variables |
JR |
22 |
|
|
23 |
Backend services urls, as well as other configurations are injected into the app as environment variables. |
|
24 |
The application automatically reads any environment variables specified in file called `.env`. |
|
25 |
|
|
26 |
To specify these variables. Create the `.env` file as follows: |
bae328
|
27 |
|
JR |
28 |
``` |
|
29 |
REACT_APP_NEWS_ENABLED=1 |
|
30 |
REACT_APP_ADOPTION_SERVICE_URL=http://localhost:8080 |
|
31 |
REACT_APP_ANIMAL_SERVICE_URL=http://localhost:8081 |
|
32 |
REACT_APP_SHELTER_SERVICE_URL=http://localhost:8082 |
|
33 |
``` |
|
34 |
|
8a7c93
|
35 |
Note that if urls for the backend services are not provided, the web-app will use fake data instead. |
bae328
|
36 |
|
8a7c93
|
37 |
In production. The environments can be passed to the container, as specified in the `Dockerfile`. |
JR |
38 |
|
|
39 |
## Development NPM Scripts |
bae328
|
40 |
|
JR |
41 |
### `npm start` |
|
42 |
|
|
43 |
Runs the app in the development mode.<br /> |
|
44 |
Open [http://localhost:3000](http://localhost:3000) to view it in the browser. |
|
45 |
|
|
46 |
The page will reload if you make edits.<br /> |
|
47 |
You will also see any lint errors in the console. |
|
48 |
|
|
49 |
### `npm test` |
|
50 |
|
|
51 |
Launches the test runner in the interactive watch mode.<br /> |
|
52 |
See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information. |
|
53 |
|
|
54 |
### `npm build` |
|
55 |
|
|
56 |
Builds the app for production to the `build` folder.<br /> |
|
57 |
It correctly bundles React in production mode and optimizes the build for the best performance. |
|
58 |
|
|
59 |
The build is minified and the filenames include the hashes.<br /> |
|
60 |
Your app is ready to be deployed! |
|
61 |
|
|
62 |
See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information. |
|
63 |
|
8a7c93
|
64 |
### `npm run start:prod` |
JR |
65 |
|
|
66 |
Starts the production server by executing `server.js`. |
|
67 |
|
|
68 |
The production server serves the files at `web-app/build`. This is the production build of the web-app. |
|
69 |
The production server also injects environment variables at run-time into `web-app/build/index.html` so that they can be read by the web-app. |
|
70 |
The injected environment variables must start with the `REACT_APP_` prefix. |
|
71 |
|
|
72 |
### `npm run lint` |
|
73 |
|
|
74 |
Checks and fixes (when possible) coding style errors. |
|
75 |
The coding style is specified in the `.eslintrc.json` file. |
|
76 |
|
bae328
|
77 |
### `npm eject` |
JR |
78 |
|
|
79 |
**Note: this is a one-way operation. Once you `eject`, you can’t go back!** |
|
80 |
|
|
81 |
If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project. |
|
82 |
|
|
83 |
Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own. |
|
84 |
|
|
85 |
You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it. |
|
86 |
|
8a7c93
|
87 |
## Container image generation for production |
JR |
88 |
|
|
89 |
You can generate production images for `1.0` and `2.0` version of the application. |
|
90 |
|
|
91 |
To build `1.0`, run `./scripts/build_image_v1`. |
|
92 |
|
|
93 |
To build `2.0`, run `./scripts/build_image_v2`. |
|
94 |
|
|
95 |
To push the generated images to quay, run `podman push quay.io/redhattraining/ossm-adopt-a-pup-webapp`. |
|
96 |
|
bae328
|
97 |
## Learn More |
JR |
98 |
|
|
99 |
You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started). |