[{"data":1,"prerenderedAt":1341},["ShallowReactive",2],{"navigation":3,"-guide-basics-handler":179,"-guide-basics-handler-surround":1336},[4,86,128,156,163],{"title":5,"path":6,"stem":7,"children":8,"icon":85},"Guide","/guide","1.guide/0.index",[9,12,48,64],{"title":10,"path":6,"stem":7,"icon":11},"Getting Started","pixel:play",{"title":5,"icon":13,"path":14,"stem":15,"children":16,"page":47},"ph:book-open-duotone","/guide/basics","1.guide/1.basics",[17,22,27,32,37,42],{"title":18,"path":19,"stem":20,"icon":21},"Request Lifecycle","/guide/basics/lifecycle","1.guide/1.basics/1.lifecycle","icon-park-outline:handle-round",{"title":23,"path":24,"stem":25,"icon":26},"Routing","/guide/basics/routing","1.guide/1.basics/2.routing","solar:routing-bold",{"title":28,"path":29,"stem":30,"icon":31},"Middleware","/guide/basics/middleware","1.guide/1.basics/3.middleware","mdi:middleware-outline",{"title":33,"path":34,"stem":35,"icon":36},"Event Handlers","/guide/basics/handler","1.guide/1.basics/4.handler","mdi:function",{"title":38,"path":39,"stem":40,"icon":41},"Sending Response","/guide/basics/response","1.guide/1.basics/5.response","tabler:json",{"title":43,"path":44,"stem":45,"icon":46},"Error Handling","/guide/basics/error","1.guide/1.basics/6.error","tabler:error-404",false,{"title":49,"icon":50,"path":51,"stem":52,"children":53,"page":47},"API","material-symbols-light:api-rounded","/guide/api","1.guide/900.api",[54,59],{"title":55,"path":56,"stem":57,"icon":58},"H3","/guide/api/h3","1.guide/900.api/1.h3","material-symbols:bolt-rounded",{"title":60,"path":61,"stem":62,"icon":63},"H3Event","/guide/api/h3event","1.guide/900.api/2.h3event","material-symbols:data-object-rounded",{"title":65,"icon":66,"path":67,"stem":68,"children":69,"page":47},"Advanced","hugeicons:more-01","/guide/advanced","1.guide/901.advanced",[70,75,80],{"title":71,"path":72,"stem":73,"icon":74},"Plugins","/guide/advanced/plugins","1.guide/901.advanced/1.plugins","clarity:plugin-line",{"title":76,"path":77,"stem":78,"icon":79},"WebSockets","/guide/advanced/websocket","1.guide/901.advanced/2.websocket","hugeicons:live-streaming-02",{"title":81,"path":82,"stem":83,"icon":84},"Nightly Builds","/guide/advanced/nightly","1.guide/901.advanced/9.nightly","game-icons:barn-owl","i-ph:book-open-duotone",{"title":87,"path":88,"stem":89,"children":90,"icon":92},"H3 Utils","/utils","2.utils/0.index",[91,93,98,103,108,113,118,123],{"title":87,"path":88,"stem":89,"icon":92},"ph:function-bold",{"title":94,"path":95,"stem":96,"icon":97},"Request","/utils/request","2.utils/1.request","material-symbols-light:input",{"title":99,"path":100,"stem":101,"icon":102},"Response","/utils/response","2.utils/2.response","material-symbols-light:output",{"title":104,"path":105,"stem":106,"icon":107},"Cookie","/utils/cookie","2.utils/3.cookie","material-symbols:cookie-outline",{"title":109,"path":110,"stem":111,"icon":112},"Security","/utils/security","2.utils/4.security","wpf:key-security",{"title":114,"path":115,"stem":116,"icon":117},"Proxy","/utils/proxy","2.utils/5.proxy","arcticons:super-proxy",{"title":119,"path":120,"stem":121,"icon":122},"More utils","/utils/more","2.utils/9.more","mingcute:plus-line",{"title":124,"path":125,"stem":126,"icon":127},"Community","/utils/community","2.utils/99.community","lets-icons:external",{"title":129,"path":130,"stem":131,"children":132,"icon":134},"Examples","/examples","4.examples/0.index",[133,135,140,144,148,152],{"title":129,"path":130,"stem":131,"icon":134},"ph:code",{"title":136,"path":137,"stem":138,"icon":139},"Cookies","/examples/handle-cookie","4.examples/handle-cookie","ph:arrow-right",{"title":141,"path":142,"stem":143,"icon":139},"Sessions","/examples/handle-session","4.examples/handle-session",{"title":145,"path":146,"stem":147,"icon":139},"Static Assets","/examples/serve-static-assets","4.examples/serve-static-assets",{"title":149,"path":150,"stem":151,"icon":139},"Stream Response","/examples/stream-response","4.examples/stream-response",{"title":153,"path":154,"stem":155,"icon":139},"Validate Data","/examples/validate-data","4.examples/validate-data",{"title":157,"path":158,"stem":159,"children":160,"icon":162},"Migration guide for v1 to v2","/migration","5.migration/0.index",[161],{"title":157,"path":158,"stem":159,"icon":162},"icons8:up-round",{"title":164,"path":165,"stem":166,"children":167,"page":-1},"Blog","/blog","99.blog",[168,171,175],{"title":164,"path":165,"stem":169,"icon":170},"99.blog/index","i-lucide-file-text",{"title":172,"path":173,"stem":174,"icon":170},"H3 1.8 - Towards the Edge of the Web","/blog/v1.8","99.blog/1.v1.8",{"title":176,"path":177,"stem":178,"icon":170},"H3 v2 beta","/blog/v2-beta","99.blog/2.v2-beta",{"id":180,"title":33,"body":181,"description":1330,"extension":1331,"meta":1332,"navigation":1333,"path":34,"seo":1334,"stem":35,"__hash__":1335},"content/1.guide/1.basics/4.handler.md",{"type":182,"value":183,"toc":1317,"icon":36},"minimark",[184,193,315,330,333,360,365,369,375,446,450,452,455,458,593,599,606,615,713,717,724,727,811,814,817,972,976,979,983,1005,1162,1166,1177,1183,1313],[185,186,187,188,192],"p",{},"You can define typed event handlers using ",[189,190,191],"code",{},"defineHandler",".",[194,195,200],"pre",{"className":196,"code":197,"language":198,"meta":199,"style":199},"language-js shiki shiki-themes github-light github-dark github-dark","import { H3, defineHandler } from \"h3\";\n\nconst app = new H3();\n\nconst handler = defineHandler((event) => \"Response\");\n\napp.get(\"/\", handler);\n","js","",[189,201,202,225,232,255,260,292,297],{"__ignoreMap":199},[203,204,207,211,215,218,222],"span",{"class":205,"line":206},"line",1,[203,208,210],{"class":209},"so5gQ","import",[203,212,214],{"class":213},"slsVL"," { H3, defineHandler } ",[203,216,217],{"class":209},"from",[203,219,221],{"class":220},"sfrk1"," \"h3\"",[203,223,224],{"class":213},";\n",[203,226,228],{"class":205,"line":227},2,[203,229,231],{"emptyLinePlaceholder":230},true,"\n",[203,233,235,238,242,245,248,252],{"class":205,"line":234},3,[203,236,237],{"class":209},"const",[203,239,241],{"class":240},"suiK_"," app",[203,243,244],{"class":209}," =",[203,246,247],{"class":209}," new",[203,249,251],{"class":250},"shcOC"," H3",[203,253,254],{"class":213},"();\n",[203,256,258],{"class":205,"line":257},4,[203,259,231],{"emptyLinePlaceholder":230},[203,261,263,265,268,270,273,276,280,283,286,289],{"class":205,"line":262},5,[203,264,237],{"class":209},[203,266,267],{"class":240}," handler",[203,269,244],{"class":209},[203,271,272],{"class":250}," defineHandler",[203,274,275],{"class":213},"((",[203,277,279],{"class":278},"sQHwn","event",[203,281,282],{"class":213},") ",[203,284,285],{"class":209},"=>",[203,287,288],{"class":220}," \"Response\"",[203,290,291],{"class":213},");\n",[203,293,295],{"class":205,"line":294},6,[203,296,231],{"emptyLinePlaceholder":230},[203,298,300,303,306,309,312],{"class":205,"line":299},7,[203,301,302],{"class":213},"app.",[203,304,305],{"class":250},"get",[203,307,308],{"class":213},"(",[203,310,311],{"class":220},"\"/\"",[203,313,314],{"class":213},", handler);\n",[316,317,318],"note",{},[185,319,320,321,323,324,329],{},"\nUsing ",[189,322,191],{}," is optional.\nYou can instead, simply use a function that accepts an ",[325,326,327],"a",{"href":61},[189,328,60],{}," and returns a response.",[185,331,332],{},"The callback function can be sync or async:",[194,334,336],{"className":196,"code":335,"language":198,"meta":199,"style":199},"defineHandler(async (event) => \"Response\");\n",[189,337,338],{"__ignoreMap":199},[203,339,340,342,344,347,350,352,354,356,358],{"class":205,"line":206},[203,341,191],{"class":250},[203,343,308],{"class":213},[203,345,346],{"class":209},"async",[203,348,349],{"class":213}," (",[203,351,279],{"class":278},[203,353,282],{"class":213},[203,355,285],{"class":209},[203,357,288],{"class":220},[203,359,291],{"class":213},[361,362,364],"h2",{"id":363},"object-syntax","Object Syntax",[366,367,368],"h3",{"id":368},"middleware",[185,370,371,372,374],{},"You can optionally register some ",[325,373,368],{"href":29}," to run with event handler to intercept request, response or errors.",[194,376,378],{"className":196,"code":377,"language":198,"meta":199,"style":199},"import { basicAuth } from \"h3\";\n\ndefineHandler({\n  middleware: [basicAuth({ password: \"test\" })],\n  handler: (event) => \"Hi!\",\n});\n",[189,379,380,393,397,404,421,441],{"__ignoreMap":199},[203,381,382,384,387,389,391],{"class":205,"line":206},[203,383,210],{"class":209},[203,385,386],{"class":213}," { basicAuth } ",[203,388,217],{"class":209},[203,390,221],{"class":220},[203,392,224],{"class":213},[203,394,395],{"class":205,"line":227},[203,396,231],{"emptyLinePlaceholder":230},[203,398,399,401],{"class":205,"line":234},[203,400,191],{"class":250},[203,402,403],{"class":213},"({\n",[203,405,406,409,412,415,418],{"class":205,"line":257},[203,407,408],{"class":213},"  middleware: [",[203,410,411],{"class":250},"basicAuth",[203,413,414],{"class":213},"({ password: ",[203,416,417],{"class":220},"\"test\"",[203,419,420],{"class":213}," })],\n",[203,422,423,426,429,431,433,435,438],{"class":205,"line":262},[203,424,425],{"class":250},"  handler",[203,427,428],{"class":213},": (",[203,430,279],{"class":278},[203,432,282],{"class":213},[203,434,285],{"class":209},[203,436,437],{"class":220}," \"Hi!\"",[203,439,440],{"class":213},",\n",[203,442,443],{"class":205,"line":294},[203,444,445],{"class":213},"});\n",[447,448],"read-more",{"to":39,"title":449},"Response Handling",[447,451],{"to":61},[366,453,454],{"id":454},"meta",[185,456,457],{},"You can define optional route meta attached to handlers, and access them from any other middleware.",[194,459,461],{"className":196,"code":460,"language":198,"meta":199,"style":199},"import { H3, defineHandler } from \"h3\";\n\nconst app = new H3();\n\napp.use((event) => {\n  console.log(event.context.matchedRoute?.meta); // { tag: \"admin\" }\n});\n\napp.get(\"/admin/**\", defineHandler({\n  meta: { tag: \"admin\" },\n  handler: (event) => \"Hi!\",\n})\n",[189,462,463,475,479,493,497,515,530,534,539,558,570,587],{"__ignoreMap":199},[203,464,465,467,469,471,473],{"class":205,"line":206},[203,466,210],{"class":209},[203,468,214],{"class":213},[203,470,217],{"class":209},[203,472,221],{"class":220},[203,474,224],{"class":213},[203,476,477],{"class":205,"line":227},[203,478,231],{"emptyLinePlaceholder":230},[203,480,481,483,485,487,489,491],{"class":205,"line":234},[203,482,237],{"class":209},[203,484,241],{"class":240},[203,486,244],{"class":209},[203,488,247],{"class":209},[203,490,251],{"class":250},[203,492,254],{"class":213},[203,494,495],{"class":205,"line":257},[203,496,231],{"emptyLinePlaceholder":230},[203,498,499,501,504,506,508,510,512],{"class":205,"line":262},[203,500,302],{"class":213},[203,502,503],{"class":250},"use",[203,505,275],{"class":213},[203,507,279],{"class":278},[203,509,282],{"class":213},[203,511,285],{"class":209},[203,513,514],{"class":213}," {\n",[203,516,517,520,523,526],{"class":205,"line":294},[203,518,519],{"class":213},"  console.",[203,521,522],{"class":250},"log",[203,524,525],{"class":213},"(event.context.matchedRoute?.meta); ",[203,527,529],{"class":528},"sCsY4","// { tag: \"admin\" }\n",[203,531,532],{"class":205,"line":299},[203,533,445],{"class":213},[203,535,537],{"class":205,"line":536},8,[203,538,231],{"emptyLinePlaceholder":230},[203,540,542,544,546,548,551,554,556],{"class":205,"line":541},9,[203,543,302],{"class":213},[203,545,305],{"class":250},[203,547,308],{"class":213},[203,549,550],{"class":220},"\"/admin/**\"",[203,552,553],{"class":213},", ",[203,555,191],{"class":250},[203,557,403],{"class":213},[203,559,561,564,567],{"class":205,"line":560},10,[203,562,563],{"class":213},"  meta: { tag: ",[203,565,566],{"class":220},"\"admin\"",[203,568,569],{"class":213}," },\n",[203,571,573,575,577,579,581,583,585],{"class":205,"line":572},11,[203,574,425],{"class":250},[203,576,428],{"class":213},[203,578,279],{"class":278},[203,580,282],{"class":213},[203,582,285],{"class":209},[203,584,437],{"class":220},[203,586,440],{"class":213},[203,588,590],{"class":205,"line":589},12,[203,591,592],{"class":213},"})\n",[447,594,596],{"to":595},"/guide/basics/routing#route-meta",[185,597,598],{},"It is also possible to add route meta when registering them to app instance.",[361,600,602,603],{"id":601},"handler-fetch","Handler ",[189,604,605],{},".fetch",[185,607,608,609,611,612,614],{},"Event handlers defined with ",[189,610,191],{},", can act as a web handler without even using ",[325,613,55],{"href":56}," class.",[194,616,618],{"className":196,"code":617,"language":198,"meta":199,"style":199},"const handler = defineHandler(async (event) => `Request: ${event.req.url}`);\n\nconst response = await handler.fetch(\"http://localhost/\");\nconsole.log(response, await response.text());\n",[189,619,620,662,666,691],{"__ignoreMap":199},[203,621,622,624,626,628,630,632,634,636,638,640,642,645,647,649,652,654,657,660],{"class":205,"line":206},[203,623,237],{"class":209},[203,625,267],{"class":240},[203,627,244],{"class":209},[203,629,272],{"class":250},[203,631,308],{"class":213},[203,633,346],{"class":209},[203,635,349],{"class":213},[203,637,279],{"class":278},[203,639,282],{"class":213},[203,641,285],{"class":209},[203,643,644],{"class":220}," `Request: ${",[203,646,279],{"class":213},[203,648,192],{"class":220},[203,650,651],{"class":213},"req",[203,653,192],{"class":220},[203,655,656],{"class":213},"url",[203,658,659],{"class":220},"}`",[203,661,291],{"class":213},[203,663,664],{"class":205,"line":227},[203,665,231],{"emptyLinePlaceholder":230},[203,667,668,670,673,675,678,681,684,686,689],{"class":205,"line":234},[203,669,237],{"class":209},[203,671,672],{"class":240}," response",[203,674,244],{"class":209},[203,676,677],{"class":209}," await",[203,679,680],{"class":213}," handler.",[203,682,683],{"class":250},"fetch",[203,685,308],{"class":213},[203,687,688],{"class":220},"\"http://localhost/\"",[203,690,291],{"class":213},[203,692,693,696,698,701,704,707,710],{"class":205,"line":257},[203,694,695],{"class":213},"console.",[203,697,522],{"class":250},[203,699,700],{"class":213},"(response, ",[203,702,703],{"class":209},"await",[203,705,706],{"class":213}," response.",[203,708,709],{"class":250},"text",[203,711,712],{"class":213},"());\n",[361,714,716],{"id":715},"lazy-handlers","Lazy Handlers",[185,718,719,720,723],{},"You can define lazy event handlers using ",[189,721,722],{},"defineLazyEventHandler",". This allow you to define some one-time logic that will be executed only once when the first request matching the route is received.",[185,725,726],{},"A lazy event handler must return an event handler.",[194,728,730],{"className":196,"code":729,"language":198,"meta":199,"style":199},"import { defineLazyEventHandler } from \"h3\";\n\ndefineLazyEventHandler(async () => {\n  await initSomething(); // Will be executed only once\n  return (event) => {\n    return \"Response\";\n  };\n});\n",[189,731,732,745,749,764,778,793,802,807],{"__ignoreMap":199},[203,733,734,736,739,741,743],{"class":205,"line":206},[203,735,210],{"class":209},[203,737,738],{"class":213}," { defineLazyEventHandler } ",[203,740,217],{"class":209},[203,742,221],{"class":220},[203,744,224],{"class":213},[203,746,747],{"class":205,"line":227},[203,748,231],{"emptyLinePlaceholder":230},[203,750,751,753,755,757,760,762],{"class":205,"line":234},[203,752,722],{"class":250},[203,754,308],{"class":213},[203,756,346],{"class":209},[203,758,759],{"class":213}," () ",[203,761,285],{"class":209},[203,763,514],{"class":213},[203,765,766,769,772,775],{"class":205,"line":257},[203,767,768],{"class":209},"  await",[203,770,771],{"class":250}," initSomething",[203,773,774],{"class":213},"(); ",[203,776,777],{"class":528},"// Will be executed only once\n",[203,779,780,783,785,787,789,791],{"class":205,"line":262},[203,781,782],{"class":209},"  return",[203,784,349],{"class":213},[203,786,279],{"class":278},[203,788,282],{"class":213},[203,790,285],{"class":209},[203,792,514],{"class":213},[203,794,795,798,800],{"class":205,"line":294},[203,796,797],{"class":209},"    return",[203,799,288],{"class":220},[203,801,224],{"class":213},[203,803,804],{"class":205,"line":299},[203,805,806],{"class":213},"  };\n",[203,808,809],{"class":205,"line":536},[203,810,445],{"class":213},[185,812,813],{},"This is useful to define some one-time logic such as configuration, class initialization, heavy computation, etc.",[185,815,816],{},"Another use-case is lazy loading route chunks:",[818,819,820,926],"CodeGroup",{},[194,821,824],{"className":196,"code":822,"filename":823,"language":198,"meta":199,"style":199},"import { H3, defineLazyEventHandler } from \"h3\";\n\nconst app = new H3();\n\napp.all(\n  \"/route\",\n  defineLazyEventHandler(() =>\n    import(\"./route.mjs\").then((mod) => mod.default),\n  ),\n);\n","app.mjs",[189,825,826,839,843,857,861,871,878,889,917,922],{"__ignoreMap":199},[203,827,828,830,833,835,837],{"class":205,"line":206},[203,829,210],{"class":209},[203,831,832],{"class":213}," { H3, defineLazyEventHandler } ",[203,834,217],{"class":209},[203,836,221],{"class":220},[203,838,224],{"class":213},[203,840,841],{"class":205,"line":227},[203,842,231],{"emptyLinePlaceholder":230},[203,844,845,847,849,851,853,855],{"class":205,"line":234},[203,846,237],{"class":209},[203,848,241],{"class":240},[203,850,244],{"class":209},[203,852,247],{"class":209},[203,854,251],{"class":250},[203,856,254],{"class":213},[203,858,859],{"class":205,"line":257},[203,860,231],{"emptyLinePlaceholder":230},[203,862,863,865,868],{"class":205,"line":262},[203,864,302],{"class":213},[203,866,867],{"class":250},"all",[203,869,870],{"class":213},"(\n",[203,872,873,876],{"class":205,"line":294},[203,874,875],{"class":220},"  \"/route\"",[203,877,440],{"class":213},[203,879,880,883,886],{"class":205,"line":299},[203,881,882],{"class":250},"  defineLazyEventHandler",[203,884,885],{"class":213},"(() ",[203,887,888],{"class":209},"=>\n",[203,890,891,894,896,899,902,905,907,910,912,914],{"class":205,"line":536},[203,892,893],{"class":209},"    import",[203,895,308],{"class":213},[203,897,898],{"class":220},"\"./route.mjs\"",[203,900,901],{"class":213},").",[203,903,904],{"class":250},"then",[203,906,275],{"class":213},[203,908,909],{"class":278},"mod",[203,911,282],{"class":213},[203,913,285],{"class":209},[203,915,916],{"class":213}," mod.default),\n",[203,918,919],{"class":205,"line":541},[203,920,921],{"class":213},"  ),\n",[203,923,924],{"class":205,"line":560},[203,925,291],{"class":213},[194,927,930],{"className":196,"code":928,"filename":929,"language":198,"meta":199,"style":199},"import { defineHandler } from \"h3\";\n\nexport default defineHandler((event) => \"Hello!\");\n","route.mjs",[189,931,932,945,949],{"__ignoreMap":199},[203,933,934,936,939,941,943],{"class":205,"line":206},[203,935,210],{"class":209},[203,937,938],{"class":213}," { defineHandler } ",[203,940,217],{"class":209},[203,942,221],{"class":220},[203,944,224],{"class":213},[203,946,947],{"class":205,"line":227},[203,948,231],{"emptyLinePlaceholder":230},[203,950,951,954,957,959,961,963,965,967,970],{"class":205,"line":234},[203,952,953],{"class":209},"export",[203,955,956],{"class":209}," default",[203,958,272],{"class":250},[203,960,275],{"class":213},[203,962,279],{"class":278},[203,964,282],{"class":213},[203,966,285],{"class":209},[203,968,969],{"class":220}," \"Hello!\"",[203,971,291],{"class":213},[361,973,975],{"id":974},"converting-to-handler","Converting to Handler",[185,977,978],{},"There are situations that you might want to convert an event handler or utility made for Node.js or another framework to H3.\nThere are built-in utils to do this.",[366,980,982],{"id":981},"from-web-handlers","From Web Handlers",[185,984,985,986,991,992,996,997,1000,1001,192],{},"Request handlers with ",[325,987,94],{"href":988,"rel":989},"https://developer.mozilla.org/en-US/docs/Web/API/Request",[990],"nofollow"," => ",[325,993,99],{"href":994,"rel":995},"https://developer.mozilla.org/en-US/docs/Web/API/Response",[990]," signuture can be converted into H3 event handlers using ",[189,998,999],{},"fromWebHandler"," utility or ",[325,1002,1004],{"href":1003},"/guide/api/h3#h3mount","H3.mount",[194,1006,1008],{"className":196,"code":1007,"language":198,"meta":199,"style":199},"import { H3, fromWebHandler } from \"h3\";\n\nexport const app = new H3();\n\nconst webHandler = (request) => new Response(\"👋 Hello!\"));\n\n// Using fromWebHandler utiliy\napp.all(\"/web\", fromWebHandler(webHandler));\n\n// Using simple wrapper\napp.all(\"/web\", event => webHandler(event.req));\n\n// Using app.mount\napp.mount(\"/web\", webHandler)\n",[189,1009,1010,1023,1027,1044,1048,1079,1083,1088,1106,1110,1115,1137,1141,1147],{"__ignoreMap":199},[203,1011,1012,1014,1017,1019,1021],{"class":205,"line":206},[203,1013,210],{"class":209},[203,1015,1016],{"class":213}," { H3, fromWebHandler } ",[203,1018,217],{"class":209},[203,1020,221],{"class":220},[203,1022,224],{"class":213},[203,1024,1025],{"class":205,"line":227},[203,1026,231],{"emptyLinePlaceholder":230},[203,1028,1029,1031,1034,1036,1038,1040,1042],{"class":205,"line":234},[203,1030,953],{"class":209},[203,1032,1033],{"class":209}," const",[203,1035,241],{"class":240},[203,1037,244],{"class":209},[203,1039,247],{"class":209},[203,1041,251],{"class":250},[203,1043,254],{"class":213},[203,1045,1046],{"class":205,"line":257},[203,1047,231],{"emptyLinePlaceholder":230},[203,1049,1050,1052,1055,1057,1059,1062,1064,1066,1068,1071,1073,1076],{"class":205,"line":262},[203,1051,237],{"class":209},[203,1053,1054],{"class":250}," webHandler",[203,1056,244],{"class":209},[203,1058,349],{"class":213},[203,1060,1061],{"class":278},"request",[203,1063,282],{"class":213},[203,1065,285],{"class":209},[203,1067,247],{"class":209},[203,1069,1070],{"class":250}," Response",[203,1072,308],{"class":213},[203,1074,1075],{"class":220},"\"👋 Hello!\"",[203,1077,1078],{"class":213},"));\n",[203,1080,1081],{"class":205,"line":294},[203,1082,231],{"emptyLinePlaceholder":230},[203,1084,1085],{"class":205,"line":299},[203,1086,1087],{"class":528},"// Using fromWebHandler utiliy\n",[203,1089,1090,1092,1094,1096,1099,1101,1103],{"class":205,"line":536},[203,1091,302],{"class":213},[203,1093,867],{"class":250},[203,1095,308],{"class":213},[203,1097,1098],{"class":220},"\"/web\"",[203,1100,553],{"class":213},[203,1102,999],{"class":250},[203,1104,1105],{"class":213},"(webHandler));\n",[203,1107,1108],{"class":205,"line":541},[203,1109,231],{"emptyLinePlaceholder":230},[203,1111,1112],{"class":205,"line":560},[203,1113,1114],{"class":528},"// Using simple wrapper\n",[203,1116,1117,1119,1121,1123,1125,1127,1129,1132,1134],{"class":205,"line":572},[203,1118,302],{"class":213},[203,1120,867],{"class":250},[203,1122,308],{"class":213},[203,1124,1098],{"class":220},[203,1126,553],{"class":213},[203,1128,279],{"class":278},[203,1130,1131],{"class":209}," =>",[203,1133,1054],{"class":250},[203,1135,1136],{"class":213},"(event.req));\n",[203,1138,1139],{"class":205,"line":589},[203,1140,231],{"emptyLinePlaceholder":230},[203,1142,1144],{"class":205,"line":1143},13,[203,1145,1146],{"class":528},"// Using app.mount\n",[203,1148,1150,1152,1155,1157,1159],{"class":205,"line":1149},14,[203,1151,302],{"class":213},[203,1153,1154],{"class":250},"mount",[203,1156,308],{"class":213},[203,1158,1098],{"class":220},[203,1160,1161],{"class":213},", webHandler)\n",[366,1163,1165],{"id":1164},"from-nodejs-handlers","From Node.js Handlers",[185,1167,1168,1169,1172,1173,1176],{},"If you have a legacy request handler with ",[189,1170,1171],{},"(req, res) => {}"," syntax made for Node.js, you can use ",[189,1174,1175],{},"fromNodeHandler"," to convert it to an h3 event handler.",[1178,1179,1180],"important",{},[185,1181,1182],{},"\nNode.js event handlers can only run within Node.js server runtime!",[194,1184,1186],{"className":196,"code":1185,"language":198,"meta":199,"style":199},"import { H3, fromNodeHandler } from \"h3\";\n\n// Force using Node.js compatibility (also works with Bun and Deno)\nimport { serve } from \"h3/node\";\n\nexport const app = new H3();\n\nconst nodeHandler = (req, res) => {\n  res.end(\"Node handlers work!\");\n};\n\napp.get(\"/web\", fromNodeHandler(nodeHandler));\n",[189,1187,1188,1201,1205,1210,1224,1228,1244,1248,1272,1287,1292,1296],{"__ignoreMap":199},[203,1189,1190,1192,1195,1197,1199],{"class":205,"line":206},[203,1191,210],{"class":209},[203,1193,1194],{"class":213}," { H3, fromNodeHandler } ",[203,1196,217],{"class":209},[203,1198,221],{"class":220},[203,1200,224],{"class":213},[203,1202,1203],{"class":205,"line":227},[203,1204,231],{"emptyLinePlaceholder":230},[203,1206,1207],{"class":205,"line":234},[203,1208,1209],{"class":528},"// Force using Node.js compatibility (also works with Bun and Deno)\n",[203,1211,1212,1214,1217,1219,1222],{"class":205,"line":257},[203,1213,210],{"class":209},[203,1215,1216],{"class":213}," { serve } ",[203,1218,217],{"class":209},[203,1220,1221],{"class":220}," \"h3/node\"",[203,1223,224],{"class":213},[203,1225,1226],{"class":205,"line":262},[203,1227,231],{"emptyLinePlaceholder":230},[203,1229,1230,1232,1234,1236,1238,1240,1242],{"class":205,"line":294},[203,1231,953],{"class":209},[203,1233,1033],{"class":209},[203,1235,241],{"class":240},[203,1237,244],{"class":209},[203,1239,247],{"class":209},[203,1241,251],{"class":250},[203,1243,254],{"class":213},[203,1245,1246],{"class":205,"line":299},[203,1247,231],{"emptyLinePlaceholder":230},[203,1249,1250,1252,1255,1257,1259,1261,1263,1266,1268,1270],{"class":205,"line":536},[203,1251,237],{"class":209},[203,1253,1254],{"class":250}," nodeHandler",[203,1256,244],{"class":209},[203,1258,349],{"class":213},[203,1260,651],{"class":278},[203,1262,553],{"class":213},[203,1264,1265],{"class":278},"res",[203,1267,282],{"class":213},[203,1269,285],{"class":209},[203,1271,514],{"class":213},[203,1273,1274,1277,1280,1282,1285],{"class":205,"line":541},[203,1275,1276],{"class":213},"  res.",[203,1278,1279],{"class":250},"end",[203,1281,308],{"class":213},[203,1283,1284],{"class":220},"\"Node handlers work!\"",[203,1286,291],{"class":213},[203,1288,1289],{"class":205,"line":560},[203,1290,1291],{"class":213},"};\n",[203,1293,1294],{"class":205,"line":572},[203,1295,231],{"emptyLinePlaceholder":230},[203,1297,1298,1300,1302,1304,1306,1308,1310],{"class":205,"line":589},[203,1299,302],{"class":213},[203,1301,305],{"class":250},[203,1303,308],{"class":213},[203,1305,1098],{"class":220},[203,1307,553],{"class":213},[203,1309,1175],{"class":250},[203,1311,1312],{"class":213},"(nodeHandler));\n",[1314,1315,1316],"style",{},"html pre.shiki code .so5gQ, html code.shiki .so5gQ{--shiki-light:#D73A49;--shiki-default:#F97583;--shiki-dark:#F97583}html pre.shiki code .slsVL, html code.shiki .slsVL{--shiki-light:#24292E;--shiki-default:#E1E4E8;--shiki-dark:#E1E4E8}html pre.shiki code .sfrk1, html code.shiki .sfrk1{--shiki-light:#032F62;--shiki-default:#9ECBFF;--shiki-dark:#9ECBFF}html pre.shiki code .suiK_, html code.shiki .suiK_{--shiki-light:#005CC5;--shiki-default:#79B8FF;--shiki-dark:#79B8FF}html pre.shiki code .shcOC, html code.shiki .shcOC{--shiki-light:#6F42C1;--shiki-default:#B392F0;--shiki-dark:#B392F0}html pre.shiki code .sQHwn, html code.shiki .sQHwn{--shiki-light:#E36209;--shiki-default:#FFAB70;--shiki-dark:#FFAB70}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);}html pre.shiki code .sCsY4, html code.shiki .sCsY4{--shiki-light:#6A737D;--shiki-default:#6A737D;--shiki-dark:#6A737D}",{"title":199,"searchDepth":227,"depth":227,"links":1318},[1319,1323,1325,1326],{"id":363,"depth":227,"text":364,"children":1320},[1321,1322],{"id":368,"depth":234,"text":368},{"id":454,"depth":234,"text":454},{"id":601,"depth":227,"text":1324},"Handler .fetch",{"id":715,"depth":227,"text":716},{"id":974,"depth":227,"text":975,"children":1327},[1328,1329],{"id":981,"depth":234,"text":982},{"id":1164,"depth":234,"text":1165},"An event handler is a function that receives an H3Event and returns a response.","md",{"icon":36},{"icon":36},{"title":33,"description":1330},"WsWtqk6_XL7HZvo7m5ZcCgBI_hR0O_Wu7gO9ufuoiYM",[1337,1339],{"title":28,"path":29,"stem":30,"description":1338,"icon":31,"children":-1},"Intercept request, response and errors using H3 middleware.",{"title":38,"path":39,"stem":40,"description":1340,"icon":41,"children":-1},"H3 automatically converts any returned value into a web response.",1750976022156]