Skip to content
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

feat: add platformProxy option to configure getPlatformProxy #12011

Merged
merged 16 commits into from
Apr 8, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/tough-dolphins-kick.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@sveltejs/adapter-cloudflare-workers": minor
"@sveltejs/adapter-cloudflare": minor
---

feat: support platform emulation configuration via the `platformProxy` adapter option
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ Cloudflare Workers specific values in the `platform` property are emulated durin

For testing the build, you should use [wrangler](https://developers.cloudflare.com/workers/cli-wrangler) **version 3**. Once you have built your site, run `wrangler pages dev .svelte-kit/cloudflare`.

Under the hood, `adapter-cloudflare` uses [getPlatformProxy](https://developers.cloudflare.com/workers/wrangler/api/#getplatformproxy) from Wrangler API for `platform` emulation. Further configuration can be passed to `getPlatformProxy` via the `platformProxy` option in your adapter config.

## Notes

Functions contained in the `/functions` directory at the project's root will _not_ be included in the deployment, which is compiled to a [single `_worker.js` file](https://developers.cloudflare.com/pages/platform/functions/#advanced-mode). Functions should be implemented as [server endpoints](https://kit.svelte.dev/docs/routing#server) in your SvelteKit app.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ Cloudflare Workers specific values in the `platform` property are emulated durin

For testing the build, you should use [wrangler](https://developers.cloudflare.com/workers/cli-wrangler) **version 3**. Once you have built your site, run `wrangler dev`.

Under the hood, `adapter-cloudflare-workers` uses [getPlatformProxy](https://developers.cloudflare.com/workers/wrangler/api/#getplatformproxy) from Wrangler API for `platform` emulation. Further configuration can be passed to `getPlatformProxy` via the `platformProxy` option in your adapter config.

## Troubleshooting

### Worker size limits
Expand Down
6 changes: 6 additions & 0 deletions packages/adapter-cloudflare-workers/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
import { Adapter } from '@sveltejs/kit';
import './ambient.js';
import { GetPlatformProxyOptions } from 'wrangler';

export default function plugin(options?: AdapterOptions): Adapter;

export interface AdapterOptions {
config?: string;
/**
* Config object passed to {@link https://developers.cloudflare.com/workers/wrangler/api/#getplatformproxy | getPlatformProxy}
* during development & preview
eltigerchino marked this conversation as resolved.
Show resolved Hide resolved
*/
platformProxy?: GetPlatformProxyOptions;
}
4 changes: 2 additions & 2 deletions packages/adapter-cloudflare-workers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const compatible_node_modules = [
];

/** @type {import('./index.js').default} */
export default function ({ config = 'wrangler.toml' } = {}) {
export default function ({ config = 'wrangler.toml', platformProxy } = {}) {
eltigerchino marked this conversation as resolved.
Show resolved Hide resolved
return {
name: '@sveltejs/adapter-cloudflare-workers',

Expand Down Expand Up @@ -144,7 +144,7 @@ export default function ({ config = 'wrangler.toml' } = {}) {
},

async emulate() {
const proxy = await getPlatformProxy();
const proxy = await getPlatformProxy(platformProxy);
const platform = /** @type {App.Platform} */ ({
env: proxy.env,
context: proxy.ctx,
Expand Down
7 changes: 7 additions & 0 deletions packages/adapter-cloudflare/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Adapter } from '@sveltejs/kit';
import './ambient.js';
import { GetPlatformProxyOptions } from 'wrangler';

export default function plugin(options?: AdapterOptions): Adapter;

Expand Down Expand Up @@ -42,6 +43,12 @@ export interface AdapterOptions {
*/
exclude?: string[];
};

/**
* Config object passed to {@link https://developers.cloudflare.com/workers/wrangler/api/#getplatformproxy | getPlatformProxy}
* during dev & preview
*/
platformProxy?: GetPlatformProxyOptions;
}

export interface RoutesJSONSpec {
Expand Down
2 changes: 1 addition & 1 deletion packages/adapter-cloudflare/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ export default function (options = {}) {
}
},
async emulate() {
const proxy = await getPlatformProxy();
const proxy = await getPlatformProxy(options.platformProxy);
const platform = /** @type {App.Platform} */ ({
env: proxy.env,
context: proxy.ctx,
Expand Down
Loading