-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: init hono adapter, reference starter
- Loading branch information
1 parent
79b1951
commit e0c9c2e
Showing
10 changed files
with
133 additions
and
25 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
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,41 @@ | ||
// import { logger } from '@gracile/internal-utils/logger.build'; | ||
|
||
import { relative } from 'node:path'; | ||
import { Readable } from 'node:stream'; | ||
import { fileURLToPath } from 'node:url'; | ||
|
||
import { CLIENT_DIST_DIR } from '../env.js'; | ||
import { type GracileAsyncMiddleware } from '../request.js'; | ||
|
||
export function honoAdapter(middleware: GracileAsyncMiddleware) { | ||
return async function honoMiddleware(context: { | ||
req: { raw: Request }; | ||
res: ResponseInit; | ||
var: unknown; | ||
}) { | ||
const result = await middleware(context.req.raw, context.var); | ||
|
||
if (result instanceof Readable) { | ||
return new Response(Readable.toWeb(result) as ReadableStream, { | ||
headers: { 'content-type': 'html' }, | ||
}); | ||
|
||
// context.res.headers.set('content-type', 'html'); | ||
// return stream(c, async (stream) => { | ||
// stream.onAbort(() => { | ||
// throw new Error('Stream aborted!'); | ||
// }); | ||
// await stream.pipe(/** @type {ReadableStream} */ Readable.toWeb(result)); | ||
// }); | ||
} | ||
|
||
if (result) return result; | ||
throw new Error('Rendering was impossible in the Hono adapter!'); | ||
}; | ||
} | ||
|
||
export function getClientDistPath(root: string) { | ||
return relative(process.cwd(), fileURLToPath(new URL(CLIENT_DIST_DIR, root))); | ||
} | ||
|
||
export { printAddressInfos } from '../utils.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
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,3 @@ | ||
// export * from '@gracile/engine/dev/.old/server'; | ||
export * from '@gracile/engine/server/adapters/hono'; | ||
export * from '@gracile/engine/server/env'; |
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 |
---|---|---|
@@ -1,4 +1,3 @@ | ||
// export * from '@gracile/engine/dev/.old/server'; | ||
export * from '@gracile/engine/server/adapters/node'; | ||
export * from '@gracile/engine/server/env'; | ||
export * from '@gracile/engine/server/node'; | ||
export * from '@gracile/engine/server/utils'; |