Skip to content
This repository was archived by the owner on Apr 5, 2024. It is now read-only.

Commit c00b1d7

Browse files
committed
WIP - Network Error - Missing CORS-Header in BE?
1 parent ee15bcc commit c00b1d7

File tree

7 files changed

+53
-3
lines changed

7 files changed

+53
-3
lines changed

webapp_frontend/package-lock.json

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

webapp_frontend/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"name": "webapp_frontend",
33
"version": "0.1.0",
44
"private": true,
5+
"proxy" :"http://localhost:8080",
56
"dependencies": {
67
"@testing-library/jest-dom": "^4.2.4",
78
"@testing-library/react": "^9.5.0",
@@ -10,6 +11,7 @@
1011
"@types/node": "^12.12.64",
1112
"@types/react": "^16.9.51",
1213
"@types/react-dom": "^16.9.8",
14+
"axios": "^0.20.0",
1315
"react": "^16.13.1",
1416
"react-dom": "^16.13.1",
1517
"react-scripts": "3.4.3",

webapp_frontend/src/api.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import Axios from "axios";
2+
import {
3+
AxiosRequestConfig,
4+
AxiosResponse,
5+
AxiosError,
6+
} from "axios";
7+
8+
const uri = "localhost:8080";
9+
10+
interface BackendHealthData {
11+
time: number
12+
}
13+
14+
function callBackendHealth():any{//BackendHealthData{
15+
return new Promise((resolve, reject) => {
16+
Axios.get("localhost:8080/health")//`${uri}/health`)
17+
.then((data) => {
18+
resolve(data.data);
19+
})
20+
.catch(((error) => {
21+
console.log(error)
22+
//reject(error);
23+
}));
24+
});
25+
}
26+
27+
export {callBackendHealth}
File renamed without changes.
File renamed without changes.

webapp_frontend/src/App.tsx renamed to webapp_frontend/src/components/App.tsx

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,19 @@
1-
import React from 'react';
2-
import logo from './logo.svg';
1+
import React, {useEffect, useState} from 'react';
2+
import logo from '../logo.svg';
33
import './App.css';
4+
import {callBackendHealth} from "../api";
45

56
function App() {
7+
const[test,setTest] = useState("test");
8+
9+
useEffect(() => {
10+
Promise.all([callBackendHealth()])
11+
.then(([backendHealthData]) => {
12+
setTest(backendHealthData)
13+
console.log(test)
14+
})
15+
}, [test]);
16+
617
return (
718
<div className="App">
819
<header className="App-header">
@@ -21,6 +32,8 @@ function App() {
2132
>
2233
Learn React
2334
</a>
35+
<button onClick={() => setTest(callBackendHealth().data)}>Test</button>
36+
<p>{test}</p>
2437
</header>
2538
</div>
2639
);

webapp_frontend/src/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React from 'react';
22
import ReactDOM from 'react-dom';
33
import './index.css';
4-
import App from './App';
4+
import App from './components/App';
55
import * as serviceWorker from './serviceWorker';
66

77
ReactDOM.render(

0 commit comments

Comments
 (0)