How to Integrate Java Backend with a TypeScript Frontend for Real-Time Data Updates? #11179
Unanswered
markwilliams21
asked this question in
Help/Questions
Replies: 1 comment
-
This is Discussions of Vuejs/core, so if you are searching for any information about Angular/React/even Java, maybe you can post in stackoverflow to ask for help. To use WS in web, see https://developer.mozilla.org/en-US/docs/Web/API/WebSocket If you are using Vue, maybe try vueuse https://vueuse.org/core/useWebSocket/ import { useWebSocket } from '@vueuse/core'
const { status, data, send, open, close } = useWebSocket('ws://xxx/chatroom') I can not provide too much info about java but maybe you can take a look on nitro(https://nitro.unjs.io/guide/websocket), which a nodejs backend framework. To make a WS serve: // routes/chatroom.ts
export default defineWebSocketHandler({
open(peer) {
console.log("[ws] open", peer);
},
message(peer, message) {
console.log("[ws] message", peer, message);
if (message.text().includes("ping")) {
peer.send("pong");
}
},
close(peer, event) {
console.log("[ws] close", peer, event);
},
error(peer, error) {
console.log("[ws] error", peer, error);
},
}); |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hi everyone,
I'm currently working on a project where I'm using Java for the backend and TypeScript for the frontend. I need to implement real-time data updates on the frontend whenever there's a change in the backend data. I've heard that WebSockets could be a good solution for this, but I'm not entirely sure how to set it up.
Here are a few specific questions I have:
Best regards,
Mark Williams
Beta Was this translation helpful? Give feedback.
All reactions