prepair redux
This commit is contained in:
@@ -1,13 +1,17 @@
|
||||
// Pfad: pages/_app.js
|
||||
import React from "react";
|
||||
import { RecoilRoot } from "recoil";
|
||||
import { Provider } from "react-redux";
|
||||
import store from "../redux/store";
|
||||
import "../styles/global.css";
|
||||
|
||||
function MyApp({ Component, pageProps }) {
|
||||
return (
|
||||
<RecoilRoot>
|
||||
<Component {...pageProps} />
|
||||
</RecoilRoot>
|
||||
<Provider store={store}>
|
||||
<RecoilRoot>
|
||||
<Component {...pageProps} />
|
||||
</RecoilRoot>
|
||||
</Provider>
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
27
pages/api/websocket.js
Normal file
27
pages/api/websocket.js
Normal file
@@ -0,0 +1,27 @@
|
||||
// /pages/api/websocket.js
|
||||
import { Server } from "ws";
|
||||
|
||||
export default function handler(req, res) {
|
||||
if (!res.socket.server.ws) {
|
||||
console.log("Starting WebSocket server");
|
||||
const wss = new Server({ server: res.socket.server });
|
||||
|
||||
wss.on("connection", (ws) => {
|
||||
console.log("New WebSocket connection");
|
||||
|
||||
ws.on("message", (message) => {
|
||||
console.log("Received:", message);
|
||||
// Beispielnachricht an den Client senden
|
||||
ws.send(JSON.stringify({ message: "Hallo von WebSocket-Server" }));
|
||||
});
|
||||
|
||||
// Schließe die Verbindung
|
||||
ws.on("close", () => {
|
||||
console.log("WebSocket connection closed");
|
||||
});
|
||||
});
|
||||
|
||||
res.socket.server.ws = wss;
|
||||
}
|
||||
res.end();
|
||||
}
|
||||
Reference in New Issue
Block a user