mirror of
https://github.com/denoland/deno.git
synced 2024-12-27 09:39:08 -05:00
20 lines
476 B
JavaScript
20 lines
476 B
JavaScript
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
|
import { parseArgs } from "@std/cli/parse-args";
|
|
|
|
const { port } = parseArgs(Deno.args, {
|
|
number: ["port"],
|
|
default: {
|
|
port: 6969,
|
|
},
|
|
});
|
|
|
|
const { serve } = Deno;
|
|
|
|
// A message-based WebSocket echo server.
|
|
serve({ port }, (request) => {
|
|
const { socket, response } = Deno.upgradeWebSocket(request);
|
|
socket.onmessage = (event) => {
|
|
socket.send(event.data);
|
|
};
|
|
return response;
|
|
});
|