-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(echo): add support for Remix framework (#5666)
- Loading branch information
Showing
4 changed files
with
48 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { EchoRequestHandler, ServeHandlerOptions } from './handler'; | ||
import { type SupportedFrameworkName } from './types'; | ||
|
||
export const frameworkName: SupportedFrameworkName = 'remix'; | ||
|
||
export const serve = ( | ||
options: ServeHandlerOptions | ||
): ((ctx: { request: Request; context?: unknown }) => Promise<Response>) => { | ||
const handler = new EchoRequestHandler({ | ||
frameworkName, | ||
...options, | ||
handler: ({ request: req }: { request: Request }) => { | ||
return { | ||
body: () => req.json(), | ||
headers: (key) => req.headers.get(key), | ||
method: () => req.method, | ||
url: () => new URL(req.url, `https://${req.headers.get('host') || ''}`), | ||
transformResponse: ({ body, status, headers }): Response => { | ||
// Handle Response polyfills | ||
// eslint-disable-next-line @typescript-eslint/naming-convention | ||
let Res: typeof Response; | ||
|
||
if (typeof Response === 'undefined') { | ||
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-var-requires | ||
Res = require('cross-fetch').Response; | ||
} else { | ||
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment | ||
Res = Response; | ||
} | ||
|
||
return new Res(body, { | ||
status, | ||
headers, | ||
}); | ||
}, | ||
}; | ||
}, | ||
}); | ||
|
||
return handler.createHandler(); | ||
}; |
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 +1 @@ | ||
export type SupportedFrameworkName = 'next' | 'express' | 'nuxt' | 'h3' | 'sveltekit'; | ||
export type SupportedFrameworkName = 'next' | 'express' | 'nuxt' | 'h3' | 'sveltekit' | 'remix'; |
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