testing things

This commit is contained in:
Luke Hagar
2024-11-11 18:51:13 -06:00
parent 78b88c6004
commit 9dfc4a306d
3 changed files with 9 additions and 6 deletions

View File

@@ -6,11 +6,12 @@ import { readFileSync } from "node:fs";
const ws = crossws({ const ws = crossws({
hooks: defineHooks({ hooks: defineHooks({
upgrade(req, socket) { upgrade(req, socket) {
if (!authorizedCheck(req)) { // if (!authorizedCheck(req)) {
socket.reject("Unauthorized") socket.reject("Unauthorized")
} else { // } else {
socket.accept() // socket.accept()
}
// }
}, },
open(peer) { open(peer) {
@@ -43,6 +44,7 @@ const port = 3000;
const index = readFileSync("./public/index.html"); const index = readFileSync("./public/index.html");
const server = createServer((req, res) => { const server = createServer((req, res) => {
console.log('hit');
res.writeHead(200); res.writeHead(200);
res.end(index); res.end(index);
}) })

View File

@@ -2,6 +2,7 @@
"name": "crossws-examples-node", "name": "crossws-examples-node",
"version": "0.0.0", "version": "0.0.0",
"private": true, "private": true,
"type": "module",
"scripts": { "scripts": {
"dev": "node ./index.js" "dev": "node ./index.js"
}, },

View File

@@ -34,7 +34,7 @@ export class AdapterHookable {
([globalRes, hook]) => { ([globalRes, hook]) => {
const hookResPromise = hook?.(arg1 as any, arg2 as any); const hookResPromise = hook?.(arg1 as any, arg2 as any);
return hookResPromise instanceof Promise return hookResPromise instanceof Promise
? hookResPromise.then((hookRes) => hookRes ?? globalRes) ? hookResPromise.then((hookRes) => hookRes || globalRes)
: hookResPromise || globalRes; : hookResPromise || globalRes;
}, },
) as Promise<any>; ) as Promise<any>;
@@ -146,7 +146,7 @@ export interface Hooks {
accept: (params?: { headers?: HeadersInit }) => void, accept: (params?: { headers?: HeadersInit }) => void,
reject: (reason: Reasons) => void, reject: (reason: Reasons) => void,
}, },
) => MaybePromise<void>; ) => MaybePromise<void | Response>;
/** A message is received */ /** A message is received */
message: (peer: Peer, message: Message) => MaybePromise<void>; message: (peer: Peer, message: Message) => MaybePromise<void>;