-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: h3 * refactor * minor --------- Co-authored-by: Thibaut LEBRETON <contact@thibaut-lebreton.fr> Co-authored-by: Horváth Dániel <nitedani@gmail.com>
- Loading branch information
1 parent
35eb1e1
commit 12a856c
Showing
9 changed files
with
248 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { vike, vike as default } from './runtime/frameworks/h3.js' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
export { vike } | ||
|
||
import { eventHandler, EventHandler } from 'h3' | ||
import type { IncomingMessage } from 'node:http' | ||
import { globalStore } from '../globalStore.js' | ||
import { createHandler } from '../handler.js' | ||
import type { VikeOptions } from '../types.js' | ||
|
||
/** | ||
* Creates an h3 event handler to process Vike requests. | ||
* | ||
* @param {VikeOptions<IncomingMessage>} [options] - Configuration options for Vike. | ||
* | ||
* @returns {EventHandler} An h3 event handler that processes requests with Vike. | ||
* | ||
* @description | ||
* This function creates an h3 event handler that integrates Vike's server-side rendering capabilities. | ||
* The handler: | ||
* 1. Checks for and handles HMR WebSocket upgrade requests. | ||
* 2. Processes regular requests using Vike's handler. | ||
* | ||
* @example | ||
* ```js | ||
* import { createApp } from 'h3' | ||
* import { vike } from 'vike-node/h3' | ||
* | ||
* const app = createApp() | ||
* app.use(vike()) | ||
* | ||
* ``` | ||
* | ||
* @remarks | ||
* - This handler directly uses Node.js' IncomingMessage and ServerResponse objects from the h3 event. | ||
* | ||
*/ | ||
function vike(options?: VikeOptions<IncomingMessage>): EventHandler { | ||
const handler = createHandler(options) | ||
return eventHandler(async (event) => { | ||
const { | ||
node: { req, res } | ||
} = event | ||
|
||
globalStore.setupHMRProxy(req) | ||
await handler({ | ||
req, | ||
res, | ||
platformRequest: req | ||
}) | ||
}) | ||
} |
Oops, something went wrong.