Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F5369914
websocket_server.mjs
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
672 B
Referenced Files
None
Subscribers
None
websocket_server.mjs
View Options
const decoder = new TextDecoder();
const port = Number(process.argv[2] || 32187);
export default {
hostname: '127.0.0.1',
port,
fetch(request, ctx) {
const url = new URL(request.url);
if (url.pathname !== '/ws') return new Response('not found', { status: 404 });
const { socket, response } = ctx.upgradeWebSocket(request);
socket.onmessage = event => {
const data = typeof event.data === 'string' ? event.data : decoder.decode(event.data);
socket.send(typeof event.data + ':' + data);
if (data === 'close') {
socket.close(1000, 'done');
setTimeout(() => ctx.stop(), 20);
}
};
return response;
}
};
File Metadata
Details
Attached
Mime Type
application/javascript
Expires
Sun, May 17, 7:30 AM (1 d, 23 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
554652
Default Alt Text
websocket_server.mjs (672 B)
Attached To
Mode
rANT Ant
Attached
Detach File
Event Timeline
Log In to Comment