diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/hero.mjs | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/src/hero.mjs b/src/hero.mjs index 61621af..4634e70 100644 --- a/src/hero.mjs +++ b/src/hero.mjs @@ -325,6 +325,26 @@ export const handlerForConnection = (table, method, path) => { return handlerFn || fallback404Handler; }; +export const makeUpgradeListener = table => async (req, socket, _head) => { + const { method, url, headers } = req; + const [ path, queryParams ] = url.split("?"); + const handlerFn = handlerForConnection(table, method, path); + + const request = { + params: { + path: {}, + query: extractQueryParams(queryParams), + }, + method, + path, + headers, + handler: handlerFn, + ref: req, + }; + + return await handlerFn(request, socket); +}; + export const makeRequestListener = table => async (req, res) => { const { status, headers, body } = await handleRequest(table, req); res.writeHead(status, headers); |