-
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.
Merge branch 'next' into com-27-js-sdk-package-config
- Loading branch information
Showing
14 changed files
with
1,382 additions
and
799 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
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,62 @@ | ||
import { RequestEvent } from '@sveltejs/kit'; | ||
import { EchoRequestHandler, ServeHandlerOptions } from './handler'; | ||
import { type SupportedFrameworkName } from './types'; | ||
|
||
export const frameworkName: SupportedFrameworkName = 'sveltekit'; | ||
|
||
export const serve = ( | ||
options: ServeHandlerOptions | ||
): ((event: RequestEvent) => Promise<Response>) & { | ||
GET: (event: RequestEvent) => Promise<Response>; | ||
POST: (event: RequestEvent) => Promise<Response>; | ||
PUT: (event: RequestEvent) => Promise<Response>; | ||
} => { | ||
const handler = new EchoRequestHandler({ | ||
frameworkName, | ||
...options, | ||
handler: (reqMethod: 'GET' | 'POST' | 'PUT' | undefined, event: RequestEvent) => { | ||
return { | ||
method: () => reqMethod || event.request.method || '', | ||
body: () => event.request.json(), | ||
headers: (key) => event.request.headers.get(key), | ||
url: () => { | ||
const protocol = process.env.NODE_ENV === 'development' ? 'http' : 'https'; | ||
|
||
return new URL(event.request.url, `${protocol}://${event.request.headers.get('host') || ''}`); | ||
}, | ||
transformResponse: ({ body, headers, status }) => { | ||
// 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 }); | ||
}, | ||
}; | ||
}, | ||
}); | ||
|
||
const baseFn = handler.createHandler(); | ||
|
||
const fn = baseFn.bind(null, undefined); | ||
type Fn = typeof fn; | ||
|
||
const handlerFn = Object.defineProperties(fn, { | ||
GET: { value: baseFn.bind(null, 'GET') }, | ||
POST: { value: baseFn.bind(null, 'POST') }, | ||
PUT: { value: baseFn.bind(null, 'PUT') }, | ||
}) as Fn & { | ||
GET: Fn; | ||
POST: Fn; | ||
PUT: Fn; | ||
}; | ||
|
||
return handlerFn; | ||
}; |
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 = 'nextjs' | 'express' | 'nuxt' | 'h3'; | ||
export type SupportedFrameworkName = 'next' | 'express' | 'nuxt' | 'h3' | 'sveltekit'; |
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 was deleted.
Oops, something went wrong.
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,17 @@ | ||
import { defineConfig } from 'tsup'; | ||
import { type SupportedFrameworkName } from './src'; | ||
|
||
const frameworks: SupportedFrameworkName[] = ['h3', 'express', 'next', 'nuxt', 'sveltekit']; | ||
|
||
export default defineConfig({ | ||
entry: ['src/index.ts', ...frameworks.map((framework) => `src/${framework}.ts`)], | ||
sourcemap: false, | ||
clean: true, | ||
treeshake: true, | ||
dts: true, | ||
format: ['cjs', 'esm'], | ||
minify: true, | ||
minifyWhitespace: true, | ||
minifyIdentifiers: true, | ||
minifySyntax: true, | ||
}); |
Oops, something went wrong.