Created
June 21, 2023 03:02
-
-
Save 0wx/4dccaa18bd509548c0cdb2168e4d41f8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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