[{"data":1,"prerenderedAt":549},["ShallowReactive",2],{"navigation":3,"/guide/resolver":56,"/guide/resolver-surround":546},[4,30],{"title":5,"_path":6,"children":7,"icon":9},"Getting Started","/guide",[8,10,14,18,22,26],{"title":5,"_path":6,"icon":9},"ph:book-open-duotone",{"title":11,"_path":12,"icon":13},"Hooks","/guide/hooks","material-symbols-light:data-object",{"title":15,"_path":16,"icon":17},"Peer","/guide/peer","mynaui:api",{"title":19,"_path":20,"icon":21},"Message","/guide/message","solar:letter-line-duotone",{"title":23,"_path":24,"icon":25},"Pub / Sub","/guide/pubsub","simple-icons:googlepubsub",{"title":27,"_path":28,"icon":29},"Resolver API","/guide/resolver","tabler:route",{"title":31,"_path":32,"children":33,"icon":35},"Adapters","/adapters",[34,36,40,44,48,52],{"title":31,"_path":32,"icon":35},"emojione-monotone:electric-plug",{"title":37,"_path":38,"icon":39},"Bun","/adapters/bun","simple-icons:bun",{"title":41,"_path":42,"icon":43},"Cloudflare","/adapters/cloudflare","devicon-plain:cloudflareworkers",{"title":45,"_path":46,"icon":47},"Deno","/adapters/deno","teenyicons:deno-solid",{"title":49,"_path":50,"icon":51},"Node.js","/adapters/node","akar-icons:node-fill",{"title":53,"_path":54,"icon":55},"SSE","/adapters/sse","clarity:two-way-arrows-line",{"_path":28,"_dir":57,"_draft":58,"_partial":58,"_locale":59,"title":27,"description":59,"icon":29,"body":60,"_type":540,"_id":541,"_source":542,"_file":543,"_stem":544,"_extension":545},"guide",false,"",{"type":61,"children":62,"toc":538},"root",[63,71,80,355,360,532],{"type":64,"tag":65,"props":66,"children":67},"element","p",{},[68],{"type":69,"value":70},"text","When integrating WebSockets with larger projects, it is often needed to dynamically route an incoming event to websocket hooks. crossws provides a very simple mechanism to do this using resolver API.",{"type":64,"tag":72,"props":73,"children":74},"tip",{},[75],{"type":64,"tag":65,"props":76,"children":77},{},[78],{"type":69,"value":79},"\nResolver supports async results. This allows implementing lazy loading.",{"type":64,"tag":81,"props":82,"children":86},"pre",{"className":83,"code":84,"language":85,"meta":59,"style":59},"language-js shiki shiki-themes material-theme-lighter material-theme material-theme-palenight","// https://crossws.h3.dev/adapters\nimport crossws from \"crossws/adapters/\u003Cadapter>\";\n\nimport { defineHooks } from \"crossws\";\n\nconst websocket = crossws({\n  async resolve(req) {\n    // TODO: Resolve hooks based on req.url, req.headers\n    // You can return undefined in case there is no match\n    return {\n      /* resolved hooks */\n    };\n  },\n});\n","js",[87],{"type":64,"tag":88,"props":89,"children":90},"code",{"__ignoreMap":59},[91,103,146,156,201,209,245,280,289,298,311,320,329,338],{"type":64,"tag":92,"props":93,"children":96},"span",{"class":94,"line":95},"line",1,[97],{"type":64,"tag":92,"props":98,"children":100},{"style":99},"--shiki-light:#90A4AE;--shiki-light-font-style:italic;--shiki-default:#546E7A;--shiki-default-font-style:italic;--shiki-dark:#676E95;--shiki-dark-font-style:italic",[101],{"type":69,"value":102},"// https://crossws.h3.dev/adapters\n",{"type":64,"tag":92,"props":104,"children":106},{"class":94,"line":105},2,[107,113,119,124,130,136,141],{"type":64,"tag":92,"props":108,"children":110},{"style":109},"--shiki-light:#39ADB5;--shiki-light-font-style:italic;--shiki-default:#89DDFF;--shiki-default-font-style:italic;--shiki-dark:#89DDFF;--shiki-dark-font-style:italic",[111],{"type":69,"value":112},"import",{"type":64,"tag":92,"props":114,"children":116},{"style":115},"--shiki-light:#90A4AE;--shiki-default:#EEFFFF;--shiki-dark:#BABED8",[117],{"type":69,"value":118}," crossws ",{"type":64,"tag":92,"props":120,"children":121},{"style":109},[122],{"type":69,"value":123},"from",{"type":64,"tag":92,"props":125,"children":127},{"style":126},"--shiki-light:#39ADB5;--shiki-default:#89DDFF;--shiki-dark:#89DDFF",[128],{"type":69,"value":129}," \"",{"type":64,"tag":92,"props":131,"children":133},{"style":132},"--shiki-light:#91B859;--shiki-default:#C3E88D;--shiki-dark:#C3E88D",[134],{"type":69,"value":135},"crossws/adapters/\u003Cadapter>",{"type":64,"tag":92,"props":137,"children":138},{"style":126},[139],{"type":69,"value":140},"\"",{"type":64,"tag":92,"props":142,"children":143},{"style":126},[144],{"type":69,"value":145},";\n",{"type":64,"tag":92,"props":147,"children":149},{"class":94,"line":148},3,[150],{"type":64,"tag":92,"props":151,"children":153},{"emptyLinePlaceholder":152},true,[154],{"type":69,"value":155},"\n",{"type":64,"tag":92,"props":157,"children":159},{"class":94,"line":158},4,[160,164,169,174,179,184,188,193,197],{"type":64,"tag":92,"props":161,"children":162},{"style":109},[163],{"type":69,"value":112},{"type":64,"tag":92,"props":165,"children":166},{"style":126},[167],{"type":69,"value":168}," {",{"type":64,"tag":92,"props":170,"children":171},{"style":115},[172],{"type":69,"value":173}," defineHooks",{"type":64,"tag":92,"props":175,"children":176},{"style":126},[177],{"type":69,"value":178}," }",{"type":64,"tag":92,"props":180,"children":181},{"style":109},[182],{"type":69,"value":183}," from",{"type":64,"tag":92,"props":185,"children":186},{"style":126},[187],{"type":69,"value":129},{"type":64,"tag":92,"props":189,"children":190},{"style":132},[191],{"type":69,"value":192},"crossws",{"type":64,"tag":92,"props":194,"children":195},{"style":126},[196],{"type":69,"value":140},{"type":64,"tag":92,"props":198,"children":199},{"style":126},[200],{"type":69,"value":145},{"type":64,"tag":92,"props":202,"children":204},{"class":94,"line":203},5,[205],{"type":64,"tag":92,"props":206,"children":207},{"emptyLinePlaceholder":152},[208],{"type":69,"value":155},{"type":64,"tag":92,"props":210,"children":212},{"class":94,"line":211},6,[213,219,224,229,235,240],{"type":64,"tag":92,"props":214,"children":216},{"style":215},"--shiki-light:#9C3EDA;--shiki-default:#C792EA;--shiki-dark:#C792EA",[217],{"type":69,"value":218},"const",{"type":64,"tag":92,"props":220,"children":221},{"style":115},[222],{"type":69,"value":223}," websocket ",{"type":64,"tag":92,"props":225,"children":226},{"style":126},[227],{"type":69,"value":228},"=",{"type":64,"tag":92,"props":230,"children":232},{"style":231},"--shiki-light:#6182B8;--shiki-default:#82AAFF;--shiki-dark:#82AAFF",[233],{"type":69,"value":234}," crossws",{"type":64,"tag":92,"props":236,"children":237},{"style":115},[238],{"type":69,"value":239},"(",{"type":64,"tag":92,"props":241,"children":242},{"style":126},[243],{"type":69,"value":244},"{\n",{"type":64,"tag":92,"props":246,"children":248},{"class":94,"line":247},7,[249,254,260,264,270,275],{"type":64,"tag":92,"props":250,"children":251},{"style":215},[252],{"type":69,"value":253},"  async",{"type":64,"tag":92,"props":255,"children":257},{"style":256},"--shiki-light:#E53935;--shiki-default:#F07178;--shiki-dark:#F07178",[258],{"type":69,"value":259}," resolve",{"type":64,"tag":92,"props":261,"children":262},{"style":126},[263],{"type":69,"value":239},{"type":64,"tag":92,"props":265,"children":267},{"style":266},"--shiki-light:#90A4AE;--shiki-light-font-style:italic;--shiki-default:#EEFFFF;--shiki-default-font-style:italic;--shiki-dark:#BABED8;--shiki-dark-font-style:italic",[268],{"type":69,"value":269},"req",{"type":64,"tag":92,"props":271,"children":272},{"style":126},[273],{"type":69,"value":274},")",{"type":64,"tag":92,"props":276,"children":277},{"style":126},[278],{"type":69,"value":279}," {\n",{"type":64,"tag":92,"props":281,"children":283},{"class":94,"line":282},8,[284],{"type":64,"tag":92,"props":285,"children":286},{"style":99},[287],{"type":69,"value":288},"    // TODO: Resolve hooks based on req.url, req.headers\n",{"type":64,"tag":92,"props":290,"children":292},{"class":94,"line":291},9,[293],{"type":64,"tag":92,"props":294,"children":295},{"style":99},[296],{"type":69,"value":297},"    // You can return undefined in case there is no match\n",{"type":64,"tag":92,"props":299,"children":301},{"class":94,"line":300},10,[302,307],{"type":64,"tag":92,"props":303,"children":304},{"style":109},[305],{"type":69,"value":306},"    return",{"type":64,"tag":92,"props":308,"children":309},{"style":126},[310],{"type":69,"value":279},{"type":64,"tag":92,"props":312,"children":314},{"class":94,"line":313},11,[315],{"type":64,"tag":92,"props":316,"children":317},{"style":99},[318],{"type":69,"value":319},"      /* resolved hooks */\n",{"type":64,"tag":92,"props":321,"children":323},{"class":94,"line":322},12,[324],{"type":64,"tag":92,"props":325,"children":326},{"style":126},[327],{"type":69,"value":328},"    };\n",{"type":64,"tag":92,"props":330,"children":332},{"class":94,"line":331},13,[333],{"type":64,"tag":92,"props":334,"children":335},{"style":126},[336],{"type":69,"value":337},"  },\n",{"type":64,"tag":92,"props":339,"children":341},{"class":94,"line":340},14,[342,347,351],{"type":64,"tag":92,"props":343,"children":344},{"style":126},[345],{"type":69,"value":346},"}",{"type":64,"tag":92,"props":348,"children":349},{"style":115},[350],{"type":69,"value":274},{"type":64,"tag":92,"props":352,"children":353},{"style":126},[354],{"type":69,"value":145},{"type":64,"tag":65,"props":356,"children":357},{},[358],{"type":69,"value":359},"If you need to change resolve function (for cases like handling HMR):",{"type":64,"tag":81,"props":361,"children":365},{"className":362,"code":363,"language":364,"meta":59,"style":59},"language-ts shiki shiki-themes material-theme-lighter material-theme material-theme-palenight","let resolveWebSocketHooks = (req) => /* ... */\n\nconst websocket = crossws({\n  async resolve(req) {\n    return resolveWebSocketHooks(req)\n  },\n});\n\n// Update reference to `resolveWebSocketHooks` later.\n","ts",[366],{"type":64,"tag":88,"props":367,"children":368},{"__ignoreMap":59},[369,409,416,443,470,495,502,517,524],{"type":64,"tag":92,"props":370,"children":371},{"class":94,"line":95},[372,377,382,386,391,395,399,404],{"type":64,"tag":92,"props":373,"children":374},{"style":215},[375],{"type":69,"value":376},"let",{"type":64,"tag":92,"props":378,"children":379},{"style":115},[380],{"type":69,"value":381}," resolveWebSocketHooks ",{"type":64,"tag":92,"props":383,"children":384},{"style":126},[385],{"type":69,"value":228},{"type":64,"tag":92,"props":387,"children":388},{"style":126},[389],{"type":69,"value":390}," (",{"type":64,"tag":92,"props":392,"children":393},{"style":266},[394],{"type":69,"value":269},{"type":64,"tag":92,"props":396,"children":397},{"style":126},[398],{"type":69,"value":274},{"type":64,"tag":92,"props":400,"children":401},{"style":215},[402],{"type":69,"value":403}," =>",{"type":64,"tag":92,"props":405,"children":406},{"style":99},[407],{"type":69,"value":408}," /* ... */\n",{"type":64,"tag":92,"props":410,"children":411},{"class":94,"line":105},[412],{"type":64,"tag":92,"props":413,"children":414},{"emptyLinePlaceholder":152},[415],{"type":69,"value":155},{"type":64,"tag":92,"props":417,"children":418},{"class":94,"line":148},[419,423,427,431,435,439],{"type":64,"tag":92,"props":420,"children":421},{"style":215},[422],{"type":69,"value":218},{"type":64,"tag":92,"props":424,"children":425},{"style":115},[426],{"type":69,"value":223},{"type":64,"tag":92,"props":428,"children":429},{"style":126},[430],{"type":69,"value":228},{"type":64,"tag":92,"props":432,"children":433},{"style":231},[434],{"type":69,"value":234},{"type":64,"tag":92,"props":436,"children":437},{"style":115},[438],{"type":69,"value":239},{"type":64,"tag":92,"props":440,"children":441},{"style":126},[442],{"type":69,"value":244},{"type":64,"tag":92,"props":444,"children":445},{"class":94,"line":158},[446,450,454,458,462,466],{"type":64,"tag":92,"props":447,"children":448},{"style":215},[449],{"type":69,"value":253},{"type":64,"tag":92,"props":451,"children":452},{"style":256},[453],{"type":69,"value":259},{"type":64,"tag":92,"props":455,"children":456},{"style":126},[457],{"type":69,"value":239},{"type":64,"tag":92,"props":459,"children":460},{"style":266},[461],{"type":69,"value":269},{"type":64,"tag":92,"props":463,"children":464},{"style":126},[465],{"type":69,"value":274},{"type":64,"tag":92,"props":467,"children":468},{"style":126},[469],{"type":69,"value":279},{"type":64,"tag":92,"props":471,"children":472},{"class":94,"line":203},[473,477,482,486,490],{"type":64,"tag":92,"props":474,"children":475},{"style":109},[476],{"type":69,"value":306},{"type":64,"tag":92,"props":478,"children":479},{"style":231},[480],{"type":69,"value":481}," resolveWebSocketHooks",{"type":64,"tag":92,"props":483,"children":484},{"style":256},[485],{"type":69,"value":239},{"type":64,"tag":92,"props":487,"children":488},{"style":115},[489],{"type":69,"value":269},{"type":64,"tag":92,"props":491,"children":492},{"style":256},[493],{"type":69,"value":494},")\n",{"type":64,"tag":92,"props":496,"children":497},{"class":94,"line":211},[498],{"type":64,"tag":92,"props":499,"children":500},{"style":126},[501],{"type":69,"value":337},{"type":64,"tag":92,"props":503,"children":504},{"class":94,"line":247},[505,509,513],{"type":64,"tag":92,"props":506,"children":507},{"style":126},[508],{"type":69,"value":346},{"type":64,"tag":92,"props":510,"children":511},{"style":115},[512],{"type":69,"value":274},{"type":64,"tag":92,"props":514,"children":515},{"style":126},[516],{"type":69,"value":145},{"type":64,"tag":92,"props":518,"children":519},{"class":94,"line":282},[520],{"type":64,"tag":92,"props":521,"children":522},{"emptyLinePlaceholder":152},[523],{"type":69,"value":155},{"type":64,"tag":92,"props":525,"children":526},{"class":94,"line":291},[527],{"type":64,"tag":92,"props":528,"children":529},{"style":99},[530],{"type":69,"value":531},"// Update reference to `resolveWebSocketHooks` later.\n",{"type":64,"tag":533,"props":534,"children":535},"style",{},[536],{"type":69,"value":537},"html .light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html.light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}",{"title":59,"searchDepth":105,"depth":105,"links":539},[],"markdown","content:1.guide:6.resolver.md","content","1.guide/6.resolver.md","1.guide/6.resolver","md",[547,548],{"_path":24,"title":23,"description":59},{"_path":32,"title":31,"description":59},1747776031395]