-
-
Notifications
You must be signed in to change notification settings - Fork 43
feat: add bunny adapter
#182
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
1aa7b44
feat(adapters): new Bunny.net adapter
sandros94 d253e05
up
sandros94 93f6e44
chore: apply automated updates
autofix-ci[bot] e9bbd24
feat: try to fallback to Deno runtime for local development
sandros94 8b0b092
chore: apply automated updates
autofix-ci[bot] 02440a8
up
sandros94 e4a2efb
fix(bunny): properly store and close local Deno.serve in dev/preview
sandros94 c86dc6f
up
sandros94 ff5289a
cleanup
sandros94 4535696
fix(bunny): wait for ready when using Deno fallback
sandros94 7ed42a2
chore: apply automated updates
autofix-ci[bot] f62fe89
Revert "fix(bunny): wait for ready when using Deno fallback"
sandros94 3b84510
feat(bunny): add waitUntil
sandros94 e466fcc
feat(bunny): prevent multiple calls to serve in Edge Scripting
sandros94 05e845f
chore: apply automated updates
autofix-ci[bot] a348e2c
fix(bunny): prefer resolvePortAndHost during dev
sandros94 03b4e51
fix(bunny): properly fallback to deno adapter
sandros94 51ba934
up
sandros94 5605c10
revert(bunny): fallback to deno adapter
sandros94 7ebe54d
fix(bunny): improve check on already started server and use remoteAdd…
sandros94 17b9030
chore: apply automated updates
autofix-ci[bot] 1c4195f
up
sandros94 c1864c7
update
pi0 99cd410
fmt
pi0 0bfc775
up
pi0 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or 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,86 @@ | ||
| import { createWaitUntil } from "../_utils.ts"; | ||
| import type { Server, ServerOptions } from "../types.ts"; | ||
| import { wrapFetch } from "../_middleware.ts"; | ||
| import { errorPlugin } from "../_plugins.ts"; | ||
|
|
||
| type MaybePromise<T> = T | Promise<T>; | ||
|
|
||
| export const FastURL: typeof globalThis.URL = URL; | ||
| export const FastResponse: typeof globalThis.Response = Response; | ||
|
|
||
| /** | ||
| * Bunny global namespace types | ||
| * | ||
| * Source: https://github.com/BunnyWay/edge-script-sdk/blob/main/libs/bunny-sdk/types/bunny.d.ts | ||
| * | ||
| * @internal | ||
| */ | ||
| declare namespace Bunny { | ||
| export const v1: BunnySDKV1; | ||
| type BunnySDKV1 = { | ||
| serve: (handler: (request: Request) => MaybePromise<Response>) => void; | ||
| }; | ||
| } | ||
|
|
||
| export function serve(options: ServerOptions): Server { | ||
| return new BunnyServer(options); | ||
| } | ||
|
|
||
| class BunnyServer implements Server { | ||
| readonly runtime = "bunny"; | ||
| readonly options: Server["options"]; | ||
| readonly fetch: (request: Request) => MaybePromise<Response>; | ||
| private _started = false; | ||
|
|
||
| #wait: ReturnType<typeof createWaitUntil> | undefined; | ||
|
|
||
| constructor(options: ServerOptions) { | ||
| this.options = { ...options, middleware: [...(options.middleware || [])] }; | ||
|
|
||
| for (const plugin of options.plugins || []) plugin(this); | ||
| errorPlugin(this); | ||
|
|
||
| const fetchHandler = wrapFetch(this); | ||
|
|
||
| this.#wait = createWaitUntil(); | ||
|
|
||
| this.fetch = (request: Request) => { | ||
| Object.defineProperties(request, { | ||
| waitUntil: { value: this.#wait?.waitUntil }, | ||
| runtime: { enumerable: true, value: { name: "bunny" } }, | ||
| ip: { | ||
| enumerable: true, | ||
| get() { | ||
| return request.headers.get("x-real-ip"); | ||
| }, | ||
| }, | ||
| }); | ||
| return fetchHandler(request); | ||
| }; | ||
|
|
||
| if (!options.manual) { | ||
| this.serve(); | ||
| } | ||
| } | ||
|
|
||
| serve() { | ||
| // Check if running in Bunny runtime | ||
| if (typeof Bunny !== "undefined" && Bunny.v1?.serve) { | ||
| // Prevent multiple calls to serve, mostly for Bunny | ||
| if (this._started) return; | ||
| this._started = true; | ||
|
|
||
| Bunny.v1.serve(this.fetch); | ||
| } else { | ||
| throw new Error("[srvx] Bunny runtime not detected."); | ||
| } | ||
| } | ||
sandros94 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| ready(): Promise<Server> { | ||
| return Promise.resolve(this); | ||
| } | ||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| async close(): Promise<void> { | ||
| await this.#wait?.wait(); | ||
| } | ||
| } | ||
This file contains hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.