Commit 6e4b77f6 authored by Markus Mößler's avatar Markus Mößler
Browse files

updated doc for react frontend stage 1

parent 23314771
Loading
Loading
Loading
Loading
Loading
+180 −0
Original line number Diff line number Diff line

# React Frontend (Stage 01) - Setup

Switch to branch `react-frontend-stage-01`,

```bash
git checkout react-frontend-stage-01
```

To solve potential dependency problems start a node container with the following volume mount and working directory,

```bash
docker run -it --rm -v $(pwd)/react-frontend/my-react-app:/app -w /app node:16 bash # run and access node container with map of local my-react-app dir to app dir 
```

Inside the node container run,

```bash
npm install # install all packages in package.json
```

Exit the node container,

```bash
exit
```

### Step 1) Start all services

Step 1.1) Start all services with rebuilded images

```bash
docker compose up --build
```

```bash
Compiled successfully!
react-frontend_1   | 
react-frontend_1   | You can now view app in the browser.
react-frontend_1   | 
react-frontend_1   |   Local:            http://localhost:3000
react-frontend_1   |   On Your Network:  http://172.18.0.3:3000
react-frontend_1   | 
react-frontend_1   | Note that the development build is not optimized.
react-frontend_1   | To create a production build, use npm run build.
react-frontend_1   | 
react-frontend_1   | webpack compiled successfully
```

Step 1.2) Potentially restart tornado-bakend service in a new terminal

```bash
docker compose restart tornado-backend
```

```bash
-----------------------------------------------------------------------------------------------------------------------------------
aidaho-tinkering-club-web-app_postgres_1          docker-entrypoint.sh postgres    Up      0.0.0.0:5432->5432/tcp,:::5432->5432/tcp
aidaho-tinkering-club-web-app_react-frontend_1    docker-entrypoint.sh npm start   Up      0.0.0.0:3000->3000/tcp,:::3000->3000/tcp
aidaho-tinkering-club-web-app_tornado-backend_1   python3 blog.py --db_host= ...   Up      0.0.0.0:8888->8888/tcp,:::8888->8888/tcp
```

### Step 2) Check tornado backend and react frontend

- [http://localhost:8888](http://localhost:8888)
- [http://localhost:3000](http://localhost:3000)

### Step 3) Edit src/App.js and save to reload.

Potentially change ownership of `./react-frontend/my-react-app/` using,

```bash
sudo chown -R username:username ./react-frontend/my-react-app/
```

Change the content of the file `./react-frontend/my-react-app/src/App.js` to,

```js
import logo from './logo.svg';
import './App.css';

function App() {
  return (
    <div className="App">
      <header className="App-header">
        <img src={logo} className="App-logo" alt="logo" />
        <p>
          Edit <code>src/App.js</code> and save to reload.
        </p>
        <a
          className="App-link"
          href="https://reactjs.org"
          target="_blank"
          rel="noopener noreferrer"
        >
          Learn React with AIDAHO!
        </a>
      </header>
    </div>
  );
}

export default App;
```

Save to reload and chekc the change on

- [http://localhost:3000](http://localhost:3000)

## Deployment

### Step 1) Configuration

For more information on the deployment see, e.g.,

- [Create react app: Available scripts](https://create-react-app.dev/docs/available-scripts)
- [Create react app: Deployment](https://create-react-app.dev/docs/deployment)

For building for relative paths, i.e., for deployment on a relative path ([see](https://create-react-app.dev/docs/deployment#building-for-relative-paths)), an entry for the homepage has to be added to the `package.json` file.

For the deployment as part of the gitlab page of this repository the following entry is used,

```json
  #"homepage": "https://mmoessler.aidaho-pages.uni-hohenheim.de/aidaho-tinkering-club-web-app/react-build/",
  "homepage": "https://aidaho-tinkering-club.uni-hohenheim.de/projects/create-react-app/",
```

### Step 2) Build the react app

Start and enter the node container

```bash
docker run -it --rm -v $(pwd)/react-frontend/my-react-app:/app -w /app node:16 bash
```

Build the react app

```bash
# build application
npm run build
```

This cerates the directory `./react-frontend/my-react-app/build`  with all neccessary files for a static deployment.

The directory contains the following files for example,

```bash
.
├── asset-manifest.json
├── favicon.ico
├── index.html
├── logo192.png
├── logo512.png
├── manifest.json
├── robots.txt
└── static
    ├── css
    │   ├── main.f855e6bc.css
    │   └── main.f855e6bc.css.map
    ├── js
    │   ├── 488.103417aa.chunk.js
    │   ├── 488.103417aa.chunk.js.map
    │   ├── main.27d96172.js
    │   ├── main.27d96172.js.LICENSE.txt
    │   └── main.27d96172.js.map
    └── media
        └── logo.6ce24c58023cc2f8fd88fe9d219db6c6.svg
```

On the server, e.g., the AIDAHO TC VM move the static built files to the nginx static files directory,

```bash
rm -rf /srv/nginx/assets/static/create-react-app/*

cp -r /srv/projects/aidaho-tinkering-club-web-app/react-frontend/my-react-app/build/* /srv/nginx/assets/static/create-react-app/
```

Baseond the current configuration of the nginx on the AIDAHO TC VM the built app is served on

- [Served AIDAHO Create React App](https://aidaho-tinkering-club.uni-hohenheim.de/projects/create-react-app/)
 No newline at end of file
+6 −0
Original line number Diff line number Diff line

# Tornado Backend (Stage 01) - Setup

Switch to branch `tornado-backend-stage-01`,

```bash
git checkout tornado-backend-stage-01
```

## Step 1) Change to `tornado-backend` directory

```bash