|
|
@ -4,53 +4,55 @@ import SockJS from "sockjs-client"; |
|
|
|
import logo from "./logo.svg"; |
|
|
|
import "./App.css"; |
|
|
|
|
|
|
|
let stomp |
|
|
|
let stomp; |
|
|
|
|
|
|
|
const connect = async (token) => { |
|
|
|
if (stomp != null) return; |
|
|
|
console.info("Connect to Websocket"); |
|
|
|
const sock = new SockJS("/api/ws"); |
|
|
|
const sock = new SockJS("http://localhost:8081/api/ws"); |
|
|
|
stomp = Stomp.over(sock); |
|
|
|
|
|
|
|
stomp.debug = (msg) => {} |
|
|
|
|
|
|
|
stomp.connect( |
|
|
|
{"X-Authorization": token}, |
|
|
|
{ "X-Authorization": token }, |
|
|
|
(frame) => { |
|
|
|
console.log("Connected", frame); |
|
|
|
|
|
|
|
const requestUrl = "/app/simple"; |
|
|
|
let params = { |
|
|
|
tratata: 1, |
|
|
|
gratata: 0 |
|
|
|
} |
|
|
|
stomp.send( |
|
|
|
requestUrl, |
|
|
|
JSON.stringify(params) |
|
|
|
); |
|
|
|
stomp.subscribe("/user/simple", (results, errors)=>{ |
|
|
|
console.log("results: ", results); |
|
|
|
console.log("errors: ", errors); |
|
|
|
gratata: 0, |
|
|
|
}; |
|
|
|
|
|
|
|
stomp.subscribe("/user/simple", (results) => { |
|
|
|
console.log(`msg from server: ${results.body}`); |
|
|
|
}); |
|
|
|
|
|
|
|
stomp.send(requestUrl, JSON.stringify(params)); |
|
|
|
}, |
|
|
|
error => { |
|
|
|
(error) => { |
|
|
|
console.error("Disconnected: ", error); |
|
|
|
} |
|
|
|
}, |
|
|
|
); |
|
|
|
} |
|
|
|
}; |
|
|
|
|
|
|
|
function App({ keycloak }) { |
|
|
|
const fetchFromApi = useCallback(async (url) => { |
|
|
|
const response = await fetch(url, { |
|
|
|
headers: { |
|
|
|
Authorization: `Bearer ${keycloak.token}`, |
|
|
|
}, |
|
|
|
}); |
|
|
|
if (response.ok) { |
|
|
|
alert(await response.text()); |
|
|
|
} else { |
|
|
|
console.error(response.statusText); |
|
|
|
} |
|
|
|
}, [keycloak.token]); |
|
|
|
const fetchFromApi = useCallback( |
|
|
|
async (url) => { |
|
|
|
const response = await fetch(url, { |
|
|
|
headers: { |
|
|
|
Authorization: `Bearer ${keycloak.token}`, |
|
|
|
}, |
|
|
|
}); |
|
|
|
if (response.ok) { |
|
|
|
alert(await response.text()); |
|
|
|
} else { |
|
|
|
console.error(response.statusText); |
|
|
|
} |
|
|
|
}, |
|
|
|
[keycloak.token], |
|
|
|
); |
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
connect(keycloak.token); |
|
|
@ -67,7 +69,7 @@ function App({ keycloak }) { |
|
|
|
className="App-link" |
|
|
|
onClick={(e) => { |
|
|
|
e.preventDefault(); |
|
|
|
fetchFromApi("/api/userinfo"); |
|
|
|
fetchFromApi("http://localhost:8081/api/userinfo"); |
|
|
|
}} |
|
|
|
> |
|
|
|
Get user email |
|
|
@ -77,7 +79,7 @@ function App({ keycloak }) { |
|
|
|
className="App-link" |
|
|
|
onClick={(e) => { |
|
|
|
e.preventDefault(); |
|
|
|
fetchFromApi("/api/users"); |
|
|
|
fetchFromApi("http://localhost:8081/api/users"); |
|
|
|
}} |
|
|
|
> |
|
|
|
Get all users |
|
|
|