-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
feat: add Bun adapter #16695
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
Open
Black-Hack
wants to merge
99
commits into
sveltejs:version-3
Choose a base branch
from
Black-Hack:feat/bun-adapter
base: version-3
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
feat: add Bun adapter #16695
Changes from all commits
Commits
Show all changes
99 commits
Select commit
Hold shift + click to select a range
a849d1d
feat(adapter-bun): implement environment variable handling and server…
Black-Hack ec55d7d
feat(adapter-bun): update build process to use Bun's JavaScript API a…
Black-Hack a443fc0
feat(adapter-bun): enhance compile options and update executable hand…
Black-Hack 7cde708
feat(adapter-bun): update build commands to require Bun and enhance e…
Black-Hack ed7ac5a
feat(adapter-bun): migrate build process to Bun and remove Rolldown c…
Black-Hack 49f9156
feat(adapter-bun): refactor manifest and server options handling in B…
Black-Hack eaa9f30
feat(adapter-bun): switch to async file reading and enhance onLoad ha…
Black-Hack 60c0651
feat(adapter-bun): enhance compile options and update build process f…
Black-Hack 53401f3
feat(adapter-bun): streamline asset handling and improve static file …
Black-Hack c7e78cf
feat(adapter-bun): optimize file handling in file_route function for …
Black-Hack 0ec0a8b
feat(adapter-bun): update envPrefix documentation for clarity on usag…
Black-Hack 0920cea
feat(adapter-bun): enhance Bun adapter with TLS support and improved …
Black-Hack 9a1658a
feat(adapter-bun): remove TLS support and related configurations from…
Black-Hack f5f23f5
feat(adapter-bun): refine server options type and remove unused utili…
Black-Hack 2a62fc8
feat(adapter-bun): improve graceful shutdown handling and remove forc…
Black-Hack e8e95f2
feat(adapter-bun): enhance error messages for protocol, host, and por…
Black-Hack b07bc2c
feat(adapter-bun): remove unused 'SHUTDOWN_TIMEOUT' from expected env…
Black-Hack d89764b
feat(adapter-bun): optimize asset handling by removing metadata gener…
Black-Hack 7f67d8e
feat(adapter-bun): enhance routing and asset handling by adding route…
Black-Hack bfda418
feat(adapter-bun): simplify route redirection handling by removing un…
Black-Hack 1f86d75
feat(adapter-bun): update serverOptions handling to ensure JSON seria…
Black-Hack 73ce708
feat(adapter-bun): simplify entrypoints and remove unnecessary build …
Black-Hack 06b69c4
feat(adapter-bun): remove build script and streamline type definition…
Black-Hack 398539e
feat(adapter-bun): update build output path and refactor buildOptions…
Black-Hack 149f7d3
feat(adapter-bun): enable read support and refactor file handling in …
Black-Hack defa665
feat(adapter-bun): add server_assets support and refactor file readin…
Black-Hack bd04683
feat(adapter-bun): refactor file handling in create_routes and update…
Black-Hack 3df0e97
feat(adapter-bun): enhance server instrumentation handling and refact…
Black-Hack 6fcc9f7
feat(adapter-bun): add server instrumentation tests and implement ins…
Black-Hack 9a755f4
feat(adapter-bun): update build options and enhance file handling in …
Black-Hack fc7d844
feat(adapter-bun): refactor file handling and enhance virtual file ma…
Black-Hack baf9359
feat(adapter-bun): change export of unix and server to const for bett…
Black-Hack 130d737
feat(adapter-bun): enhance build options and add bytes_env utility fo…
Black-Hack e65353c
feat(adapter-bun): fix port environment variable handling for better …
Black-Hack 8133d21
feat(adapter-bun): implement routes utility functions and enhance man…
Black-Hack 2cde6d9
feat(adapter-bun): enhance routing and prerendering with file_respons…
Black-Hack 421de00
feat(adapter-bun): change redirect status from 301 to 308 for improve…
Black-Hack bbcc645
feat(adapter-bun): update response handling to use RouteHandler for c…
Black-Hack 401f9f2
feat(tests): add tests for serving static files and update server res…
Black-Hack 77d051e
feat(routes-util): enhance encode_pathname to handle asterisks in pat…
Black-Hack 7091dae
feat(routes-util): streamline response handling in client and prerend…
Black-Hack 06226e4
fix(routes-util): correct appPath reference in client_asset cache con…
Black-Hack 3cce96f
feat(adapter-bun): enhance get_embed_entries and get_no_embed_entries…
Black-Hack cbca228
feat(adapter-bun): enhance asset handling and add support for static …
Black-Hack 1d7a1f0
feat(adapter-bun): refactor runtime configuration handling and remove…
Black-Hack 7625896
fix(adapter-bun): remove quiet-buns-scope changeset file
Black-Hack d0d93c2
feat(adapter-bun): add validation for wildcard filenames and update t…
Black-Hack 9a7ecaa
feat(adapter-bun): add Playwright tests for browser and server rendering
Black-Hack 0f733e4
feat(adapter-bun): update browser and server tests for improved outpu…
Black-Hack 1904b9c
fix(adapter-bun): simplify pathname encoding by removing wildcard rep…
Black-Hack 4b37413
refactor(adapter-bun): streamline log handling for builder messages
Black-Hack ddd8915
Delete packages/adapter-bun/LICENSE
teemingc b2a4391
Merge branch 'version-3' into feat/bun-adapter
teemingc 67343d3
fix: force-close connections after SHUTDOWN_TIMEOUT
Nic-Polumeyv 65d5464
fix: log Bun build diagnostics via builder.log
Nic-Polumeyv 0e92dd6
feat: respect buildOptions.splitting
Nic-Polumeyv 5da1d4f
fix: only treat ENOENT as an absent output directory
Nic-Polumeyv 32748fa
fix: serve static files at the paths browsers request
Nic-Polumeyv 90fce97
fix: serve /dir and extensionless .html like sirv
Nic-Polumeyv 8986a87
fix: percent-encode the trailing-slash redirect location
Nic-Polumeyv c481a61
fix: stop serving dotfiles except .well-known
Nic-Polumeyv 7fe7313
fix: reject wildcards in prerendered route paths
Nic-Polumeyv 68f1873
fix: return 400 for unsupported forwarded protocol schemes
Nic-Polumeyv dcfd13a
fix: ignore proxy headers that are present but empty
Nic-Polumeyv 4ec9d49
chore: remove unreachable XFF_DEPTH check
Nic-Polumeyv a147874
chore: fix the ROUTES route table type
Nic-Polumeyv 794418b
chore: correct the buildOptions default
Nic-Polumeyv 211f4ce
chore: drop the eslint-disable comment from generated routes
Nic-Polumeyv 4df7ecd
chore: fix the lockfile after the version-3 merge
Nic-Polumeyv 57384d5
feat: revalidate static assets with build-time ETags
Nic-Polumeyv ac4f83a
feat: precompress option with accept-encoding negotiation
Nic-Polumeyv d48e89a
fix: preserve last-modified revalidation
Nic-Polumeyv e7bf26f
fix: answer HEAD requests on trailing-slash redirects
Nic-Polumeyv b08c74f
chore: deduplicate route generation
Nic-Polumeyv 6fcf8df
Update packages/adapter-bun/test/apps/basic/tsconfig.json
Nic-Polumeyv 7334630
fix: restore the test app tsconfig
Nic-Polumeyv cd6c8d2
test: cover the root base, conditional-request wildcards, and readdir…
Nic-Polumeyv dbef236
test: collapse the boolean spellings into one pass
Nic-Polumeyv b72a83a
fix: answer HEAD requests on prerendered redirects
Nic-Polumeyv e1203a3
Update documentation/docs/25-build-and-deploy/45-adapter-bun.md
Nic-Polumeyv 40e7276
fix: address review findings across route keys, generation, and shutdown
Nic-Polumeyv d0eb408
chore: apply review suggestions
Nic-Polumeyv 7a4ca92
chore: hoist type imports into @import comments
Nic-Polumeyv acf5203
chore: silence no-control-regex on the path encode set
Nic-Polumeyv 4e634e2
Merge remote-tracking branch 'origin/version-3' into pr-16695
Nic-Polumeyv 181fab5
Merge remote-tracking branch 'origin/version-3' into pr-16695
Nic-Polumeyv 344b222
fix: assume https for proxied requests without a protocol header
Nic-Polumeyv 7a6743f
fix: return undefined from getClientAddress when there is no peer add…
Nic-Polumeyv 362687a
fix: remove a stale socket file before listening
Nic-Polumeyv 5bc7987
fix: allow BODY_SIZE_LIMIT=Infinity to disable the limit
Nic-Polumeyv d56bd6f
fix: rename IDLE_TIMEOUT to CONNECTION_IDLE_TIMEOUT
Nic-Polumeyv 765570b
fix: always set an explicit port so Bun ignores unprefixed PORT varia…
Nic-Polumeyv 757c0bb
fix: resolve asset directories from the module URL instead of Bun.main
Nic-Polumeyv e34cfe1
fix: emit the instrumentation start module as an entrypoint so asset …
Nic-Polumeyv da51742
Merge remote-tracking branch 'origin/version-3' into pr-16695
Nic-Polumeyv ea4cc13
readability and slop cleanups
Nic-Polumeyv b92a53b
merge version-3 into pr-16695
Nic-Polumeyv 50b89dd
read config off the builder directly, config.kit is deprecated after …
Nic-Polumeyv b5a372d
work around Bun duplicating side-effect-only chunks
Nic-Polumeyv 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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| '@sveltejs/adapter-bun': minor | ||
| --- | ||
|
|
||
| feat: add a Bun-native adapter with static file serving and single-executable support |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| name: Platform Tests (Bun) | ||
|
|
||
| on: | ||
| workflow_dispatch: | ||
| inputs: | ||
| sha: | ||
| description: 'Commit SHA to test' | ||
| required: false | ||
| default: '' | ||
| workflow_call: | ||
| inputs: | ||
| sha: | ||
| description: 'Commit SHA to test' | ||
| required: false | ||
| type: string | ||
| default: '' | ||
|
|
||
| permissions: | ||
| contents: read | ||
|
|
||
| env: | ||
| PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: '1' | ||
|
|
||
| jobs: | ||
| test-basic: | ||
| if: github.repository == 'sveltejs/kit' | ||
| runs-on: ubuntu-latest | ||
| timeout-minutes: 15 | ||
| steps: | ||
| - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 | ||
| with: | ||
| ref: ${{ inputs.sha || github.sha }} | ||
| persist-credentials: false | ||
|
|
||
| - uses: ./.github/actions/node-setup | ||
|
|
||
| - uses: oven-sh/setup-bun@0c5077e51419868618aeaa5fe8019c62421857d6 # v2.2.0 | ||
| with: | ||
| bun-version: 1.3.14 | ||
|
|
||
| - uses: ./.github/actions/platform-test | ||
| with: | ||
| test-app-dir: packages/adapter-bun/test/apps/basic | ||
| os: ubuntu-latest | ||
|
|
||
| - name: Test compiled executable | ||
| working-directory: packages/adapter-bun/test/apps/basic | ||
| env: | ||
| COMPILE: 'true' | ||
| run: pnpm test:platform | ||
|
|
||
| - name: Compile optimized cross-target executable | ||
| working-directory: packages/adapter-bun/test/apps/basic | ||
| env: | ||
| ADVANCED_COMPILE: 'true' | ||
| COMPILE_TARGET: 'bun-linux-x64' | ||
| run: | | ||
| bun run --bun build | ||
| test -x build/advanced-app |
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
254 changes: 254 additions & 0 deletions
254
documentation/docs/25-build-and-deploy/45-adapter-bun.md
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,254 @@ | ||
| --- | ||
| title: Bun servers | ||
| --- | ||
|
|
||
| [`adapter-bun`](https://github.com/sveltejs/kit/tree/main/packages/adapter-bun) builds a SvelteKit application into a standalone [Bun](https://bun.com/) server. The generated server uses `Bun.serve` for requests and `Bun.file` responses for client assets, prerendered output, and files read with [`read`](https://svelte.dev/docs/kit/$app-server#read) from `$app/server`. | ||
|
|
||
| ## Usage | ||
|
|
||
| Install the adapter: | ||
|
|
||
| ```sh | ||
| bun add -D @sveltejs/adapter-bun | ||
| ``` | ||
|
|
||
| Configure it in `vite.config.js`: | ||
|
|
||
| ```js | ||
| // @errors: 2307 2554 | ||
| /// file: vite.config.js | ||
| import adapter from '@sveltejs/adapter-bun'; | ||
| import { sveltekit } from '@sveltejs/kit/vite'; | ||
| import { defineConfig } from 'vite'; | ||
|
|
||
| export default defineConfig({ | ||
| plugins: [ | ||
| sveltekit({ | ||
| adapter: adapter() | ||
| }) | ||
| ] | ||
| }); | ||
| ``` | ||
|
|
||
| The adapter calls Bun's build API, so the production build itself must run in Bun. The `--bun` flag overrides Vite's Node.js shebang: | ||
|
|
||
| ```sh | ||
| bun run --bun build | ||
| ``` | ||
|
|
||
| The default build is written to `build`. Start it with: | ||
|
|
||
| ```sh | ||
| bun ./build | ||
| ``` | ||
|
|
||
| The JavaScript server, client files, and prerendered files in the output directory are all required at runtime. Application imports are processed according to Bun's bundler behavior. | ||
|
|
||
| Client assets and prerendered output are registered as native Bun routes. Only `GET` and `HEAD` requests are served by those routes; other methods continue to SvelteKit. Every asset carries an ETag computed during the build, so conditional requests revalidate with an empty `304` response. Bun supplies MIME types, byte ranges for filesystem-backed files, and streaming without buffering every asset in memory. Files below SvelteKit's `immutable` directory receive `Cache-Control: public,max-age=31536000,immutable`. | ||
|
|
||
| > [!NOTE] Bun treats `*` in a route pathname as a wildcard. The adapter rejects client and prerendered filenames that contain a literal `*`; rename those files before building. | ||
|
|
||
| ## Options | ||
|
|
||
| ```js | ||
| // @errors: 2307 2554 | ||
| /// file: vite.config.js | ||
| import adapter from '@sveltejs/adapter-bun'; | ||
| import { sveltekit } from '@sveltejs/kit/vite'; | ||
| import { defineConfig } from 'vite'; | ||
|
|
||
| export default defineConfig({ | ||
| plugins: [ | ||
| sveltekit({ | ||
| adapter: adapter({ | ||
| out: 'build', | ||
| envPrefix: '', | ||
| serverOptions: { | ||
| idleTimeout: 30 | ||
| }, | ||
| buildOptions: { | ||
| sourcemap: 'external' | ||
| } | ||
| }) | ||
| }) | ||
| ] | ||
| }); | ||
| ``` | ||
|
|
||
| ### out | ||
|
|
||
| The output directory. It defaults to `build`. | ||
|
|
||
| ### precompress | ||
|
|
||
| Set `precompress: true` to generate `.br` and `.gz` variants of client and prerendered assets during the build. The generated routes negotiate `Accept-Encoding` per request, preferring brotli over gzip, and each variant carries its own ETag. The option is ignored when `buildOptions.compile` is set, because embedded assets are imported by identity path. | ||
|
|
||
| ### envPrefix | ||
|
|
||
| A prefix for every deployment environment variable documented below. This is useful when the unprefixed names conflict with variables managed by your host: | ||
|
|
||
| ```js | ||
| adapter({ envPrefix: 'MY_APP_' }); | ||
| ``` | ||
|
|
||
| ```sh | ||
| MY_APP_HOST=127.0.0.1 MY_APP_PORT=4000 bun ./build | ||
| ``` | ||
|
|
||
| When a prefix is configured, the server fails at startup if it finds an unknown environment variable with that prefix. This catches collisions and misspellings. | ||
|
|
||
| ### serverOptions | ||
|
|
||
| JSON-serializable defaults passed to `Bun.serve`. The supported properties are: | ||
|
|
||
| - `hostname` | ||
| - `port` | ||
| - `unix` | ||
| - `reusePort` | ||
| - `ipv6Only` | ||
| - `idleTimeout` | ||
| - `maxRequestBodySize` | ||
| - `development` | ||
|
|
||
| Environment variables take precedence over these defaults. A configured Unix socket takes precedence over `hostname`, `port`, `reusePort`, and `ipv6Only`. | ||
|
|
||
| The generated server owns `fetch` and `routes`. It does not expose `websocket`, `error`, TLS, HTTP/3, or HTTP/1 configuration through `serverOptions`. Use a custom Bun integration if your application requires those `Bun.serve` options. | ||
|
|
||
| ### buildOptions | ||
|
|
||
| Advanced Bun build settings can be supplied with `buildOptions`. The adapter currently accepts `sourcemap`, `minify`, `bytecode`, `banner`, `footer`, `drop`, `features`, `optimizeImports`, `splitting`, and `compile`. Code splitting is enabled by default; `splitting: false` bundles the server into a single file, which works around [`Bun.build` output path collisions](https://github.com/oven-sh/bun/issues/17674) on applications whose module graph produces identically-hashed chunks. | ||
|
|
||
| The generated entrypoint, output directory, top-level `target`, and module `format` are reserved. Generated servers target Bun and use ESM. Source maps default to `external`; set `sourcemap: 'none'` to disable them. | ||
|
|
||
| #### Compiled executables | ||
|
|
||
| Set `compile: true` to generate a single executable at `<out>/server`: | ||
|
|
||
| ```js | ||
| adapter({ | ||
| buildOptions: { | ||
| compile: true | ||
| } | ||
| }); | ||
| ``` | ||
|
|
||
| Build and run it without a separately installed Bun runtime: | ||
|
|
||
| ```sh | ||
| bun run --bun build | ||
| ./build/server | ||
| ``` | ||
|
|
||
| The executable embeds the server code, client assets, prerendered output, and Bun runtime. `compile` can also be a Bun target string, which keeps the default `server` filename, or an options object. To change the executable name or cross-compile, provide an options object: | ||
|
|
||
| ```js | ||
| adapter({ | ||
| out: 'dist', | ||
| buildOptions: { | ||
| compile: { | ||
| outfile: 'application', | ||
| target: 'bun-linux-x64' | ||
| }, | ||
| minify: true, | ||
| bytecode: true, | ||
| sourcemap: 'linked' | ||
| } | ||
| }); | ||
| ``` | ||
|
|
||
| The result in this example is `dist/application`. Platform targets, native dependencies, and other limitations follow [Bun's executable compilation rules](https://bun.com/docs/bundler/executables). | ||
|
|
||
| ## Environment variables | ||
|
|
||
| Bun loads `.env` files automatically. If `envPrefix` is set, add that prefix to each name in this section. | ||
|
|
||
| ### Listener | ||
|
|
||
| `HOST` and `PORT` configure the TCP listener. Without either value or a `serverOptions` default, the server listens on port `3000`. | ||
|
|
||
| ```sh | ||
| HOST=127.0.0.1 PORT=4000 bun ./build | ||
| ``` | ||
|
|
||
| `SOCKET_PATH` selects a Unix domain socket instead. When it is present, TCP-only options are ignored: | ||
|
|
||
| ```sh | ||
| SOCKET_PATH=/tmp/sveltekit.sock bun ./build | ||
| ``` | ||
|
|
||
| `REUSE_PORT` enables Bun's `reusePort` option and `IPV6_ONLY` enables `ipv6Only`. Boolean variables accept `1`, `true`, `yes`, and `on`, or `0`, `false`, `no`, and `off`, without regard to letter case. | ||
|
|
||
| ### Request limits and diagnostics | ||
|
|
||
| `BODY_SIZE_LIMIT` controls `Bun.serve`'s `maxRequestBodySize`. It defaults to `512K`. The value must resolve to a whole number of bytes and may use a case-insensitive binary `K`, `M`, or `G` suffix, such as `768K` or `1.5M`. `Infinity` disables the limit. | ||
|
|
||
| `CONNECTION_IDLE_TIMEOUT` sets Bun's per-request inactivity timeout in seconds. It must be an integer from `0` through `255`; `0` disables the timeout. The generated handler disables the timeout for responses whose content type starts with `text/event-stream` and also adds `X-Accel-Buffering: no`. It is deliberately not called `IDLE_TIMEOUT`, which on adapter-node means something different (shut the server down after N seconds without requests). | ||
|
|
||
| `DEVELOPMENT` enables Bun's development-mode error pages. It defaults to `false` for the generated server. | ||
|
|
||
| ### Public origin behind a proxy | ||
|
|
||
| If [`paths.origin`](configuration#paths) is configured, that value is the trusted origin for every request. Otherwise, the adapter derives the host from the `Host` header and assumes the scheme is `https`, since production deployments usually terminate TLS upstream. Configure `paths.origin` or `PROTOCOL_HEADER` if that assumption is wrong, for example when serving plain HTTP directly. | ||
|
|
||
| Behind a trusted reverse proxy, `PROTOCOL_HEADER`, `HOST_HEADER`, and `PORT_HEADER` name headers that contain the public scheme, host, and port: | ||
|
|
||
| ```sh | ||
| PROTOCOL_HEADER=x-forwarded-proto \ | ||
| HOST_HEADER=x-forwarded-host \ | ||
| PORT_HEADER=x-forwarded-port \ | ||
| bun ./build | ||
| ``` | ||
|
|
||
| The protocol header must contain `http` or `https`, without a colon. The port header must contain a number. Invalid values produce a `400 Bad Request` response. A header that is present but empty is ignored in favour of the fallback. | ||
|
|
||
| > [!CAUTION] Only trust forwarded headers when requests can reach the server through a proxy you control. A direct client can spoof these headers. | ||
|
|
||
| ### Client addresses behind a proxy | ||
|
|
||
| [`event.getClientAddress()`](https://svelte.dev/docs/kit/@sveltejs-kit#RequestEvent) uses `server.requestIP(request).address` by default. Set `ADDRESS_HEADER` to the name of a trusted proxy header when the direct peer is a proxy: | ||
|
|
||
| ```sh | ||
| ADDRESS_HEADER=true-client-ip bun ./build | ||
| ``` | ||
|
|
||
| For `x-forwarded-for`, also set `XFF_DEPTH` to the number of trusted proxies. The default depth is `1`, and the adapter selects from the right side of the comma-separated list so client-supplied entries to the left cannot change the trusted result: | ||
|
|
||
| ```sh | ||
| ADDRESS_HEADER=x-forwarded-for XFF_DEPTH=2 bun ./build | ||
| ``` | ||
|
|
||
| `XFF_DEPTH` must be an integer of at least `1`. `getClientAddress()` throws if the configured header is absent or contains fewer addresses than the configured depth. | ||
|
|
||
| ## Platform API | ||
|
|
||
| The request event's `platform` property exposes the original Web API request received by Bun and the Bun server instance: | ||
|
|
||
| ```js | ||
| /** @type {import('./$types').RequestHandler} */ | ||
| export function GET({ getClientAddress, platform }) { | ||
| return Response.json({ | ||
| address: getClientAddress(), | ||
| requestUrl: platform.request.url, | ||
| serverId: platform.server.id, | ||
| pendingRequests: platform.server.pendingRequests, | ||
| pendingWebSockets: platform.server.pendingWebSockets | ||
| }); | ||
| } | ||
| ``` | ||
|
|
||
| `platform.request` remains the original request even when the adapter normalizes the request URL to a configured or proxy-derived public origin before passing it to SvelteKit. | ||
|
|
||
| ## Graceful shutdown | ||
|
|
||
| On `SIGINT` or `SIGTERM`, the generated server calls `server.stop()`. Bun stops accepting new connections and the adapter waits for pending requests before emitting a `sveltekit:shutdown` process event with the signal name: | ||
|
|
||
| ```js | ||
| process.on('sveltekit:shutdown', async (reason) => { | ||
| await jobs.stop(); | ||
| await db.close(); | ||
| }); | ||
| ``` | ||
|
|
||
| Connections that are still open after `SHUTDOWN_TIMEOUT` seconds are closed forcefully, so idle connections such as open event streams cannot delay the shutdown indefinitely. The value must be a non-negative integer and defaults to `30`. | ||
|
|
||
| Sending a second shutdown signal forces the process to exit with status `1`. |
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,5 @@ | ||
| .DS_Store | ||
| node_modules | ||
| /files | ||
| coverage/ | ||
|
|
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,7 @@ | ||
| # @sveltejs/adapter-bun | ||
|
|
||
| ## 1.0.0-next.0 | ||
|
|
||
| ### Patch Changes | ||
|
|
||
| - Initial release |
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,30 @@ | ||
| # @sveltejs/adapter-bun | ||
|
|
||
| SvelteKit adapter that builds a standalone server for the [Bun](https://bun.com/) runtime. | ||
|
|
||
| ```sh | ||
| bun add -D @sveltejs/adapter-bun | ||
| ``` | ||
|
|
||
| ```js | ||
| import adapter from '@sveltejs/adapter-bun'; | ||
| import { sveltekit } from '@sveltejs/kit/vite'; | ||
| import { defineConfig } from 'vite'; | ||
|
|
||
| export default defineConfig({ | ||
| plugins: [sveltekit({ adapter: adapter() })] | ||
| }); | ||
| ``` | ||
|
|
||
| Build with `bun run --bun build`, then run the default output with `bun ./build`. | ||
|
|
||
| See the [adapter-bun documentation](https://svelte.dev/docs/kit/adapter-bun) for configuration, | ||
| environment variables, compiled executables, proxy setup, and the Bun-specific platform API. | ||
|
|
||
| ## Changelog | ||
|
|
||
| [View the package changelog](https://github.com/sveltejs/kit/blob/main/packages/adapter-bun/CHANGELOG.md). | ||
|
|
||
| ## License | ||
|
|
||
| [MIT](LICENSE) | ||
Oops, something went wrong.
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.