Skip to content

Instantly share code, notes, and snippets.

@walpolsh
Created October 14, 2021 13:33
Show Gist options
  • Select an option

  • Save walpolsh/b5cc7552cfbd407a66d4be9efd2ddd24 to your computer and use it in GitHub Desktop.

Select an option

Save walpolsh/b5cc7552cfbd407a66d4be9efd2ddd24 to your computer and use it in GitHub Desktop.
import React, { useEffect } from "react";
import { io } from "socket.io-client";
import "./App.css";
const endpoint = "http://127.0.0.1:5000/";
const socket = io(endpoint, {
cors: {
origin: "https://example.com",
methods: ["GET", "POST"],
allowedHeaders: ["my-custom-header"],
credentials: true,
},
});
function App() {
useEffect(() => {
socket.on("connect", (data) => {
console.log(data); // true
socket.emit("my event", { data: "I'm connected!" });
});
}, []);
return <div className="App">flask server test</div>;
}
export default App;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment