Skip to content

Commit

Permalink
feat(echo): add support for Remix framework (#5666)
Browse files Browse the repository at this point in the history
  • Loading branch information
rifont authored Jun 3, 2024
1 parent c065680 commit fe793d1
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 2 deletions.
5 changes: 5 additions & 0 deletions packages/echo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@
"require": "./dist/sveltekit.js",
"import": "./dist/sveltekit.mjs",
"types": "./dist/sveltekit.d.ts"
},
"./remix": {
"require": "./dist/remix.js",
"import": "./dist/remix.mjs",
"types": "./dist/remix.d.ts"
}
},
"devDependencies": {
Expand Down
41 changes: 41 additions & 0 deletions packages/echo/src/remix.ts
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();
};
2 changes: 1 addition & 1 deletion packages/echo/src/types/framework.types.ts
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';
2 changes: 1 addition & 1 deletion packages/echo/tsup.config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { defineConfig } from 'tsup';
import { type SupportedFrameworkName } from './src';

const frameworks: SupportedFrameworkName[] = ['h3', 'express', 'next', 'nuxt', 'sveltekit'];
const frameworks: SupportedFrameworkName[] = ['h3', 'express', 'next', 'nuxt', 'sveltekit', 'remix'];

export default defineConfig({
entry: ['src/index.ts', ...frameworks.map((framework) => `src/${framework}.ts`)],
Expand Down

0 comments on commit fe793d1

Please sign in to comment.