Skip to content

Instantly share code, notes, and snippets.

@0wx
Created June 21, 2023 03:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 0wx/4dccaa18bd509548c0cdb2168e4d41f8 to your computer and use it in GitHub Desktop.
Save 0wx/4dccaa18bd509548c0cdb2168e4d41f8 to your computer and use it in GitHub Desktop.
(async() => {
while(true) {
await new Promise((res) => setTimeout(res, 1000))
if(typeof io === 'undefined') continue
const socket = io('http://localhost:3000')
socket.on('connect', () => {
console.log('Connected')
})
socket.on('data', async (data, cb) => {
const response = await fetch(data.url)
if (data.type === 'json') {
const json = await response.json()
cb(json)
} else {
console.log(response)
const text = await response.text()
cb(text)
}
})
socket.on('disconnect', () => {
console.log('Disconnected')
})
break
}
})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment