forked from cloudflare/workers-sdk
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Only use router worker when assets is enabled (cloudflare#115)
* Added getEntryWorker function * Remove unnecessary logic in middleware * Removed unnecessary async * Used consistent node:path import
- Loading branch information
1 parent
1e7ee4a
commit b1e5987
Showing
4 changed files
with
31 additions
and
22 deletions.
There are no files selected for viewing
6 changes: 0 additions & 6 deletions
6
...ages/vite-plugin-cloudflare/src/assets.ts → ...s/vite-plugin-cloudflare/src/constants.ts
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,9 +1,3 @@ | ||
import type { Miniflare } from 'miniflare'; | ||
|
||
export const ROUTER_WORKER_NAME = '__router-worker__'; | ||
export const ASSET_WORKER_NAME = '__asset-worker__'; | ||
export const ASSET_WORKERS_COMPATIBILITY_DATE = '2024-10-04'; | ||
|
||
export function getRouterWorker(miniflare: Miniflare) { | ||
return miniflare.getWorker(ROUTER_WORKER_NAME); | ||
} |
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,22 @@ | ||
import assert from 'node:assert'; | ||
import { ROUTER_WORKER_NAME } from './constants'; | ||
import type { ResolvedPluginConfig } from './plugin-config'; | ||
import type { Miniflare } from 'miniflare'; | ||
|
||
export function getDevEntryWorker( | ||
resolvedPluginConfig: ResolvedPluginConfig, | ||
miniflare: Miniflare, | ||
) { | ||
const entryWorkerConfig = | ||
resolvedPluginConfig.type === 'assets-only' | ||
? resolvedPluginConfig.config | ||
: resolvedPluginConfig.workers[ | ||
resolvedPluginConfig.entryWorkerEnvironmentName | ||
]; | ||
|
||
assert(entryWorkerConfig, 'Unexpected error: No entry worker configuration'); | ||
|
||
return entryWorkerConfig.assets | ||
? miniflare.getWorker(ROUTER_WORKER_NAME) | ||
: miniflare.getWorker(entryWorkerConfig.name); | ||
} |
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