@@ -25,25 +25,21 @@ export const CURRENT_VERSION_ID = "current";
2525 * @param request
2626 * @returns
2727 */
28- export function maybeGetSkewProtectionResponse (
29- request : Request ,
30- assets : Fetcher | undefined
31- ) : Promise < Response > | Response | undefined {
28+ export function maybeGetSkewProtectionResponse ( request : Request ) : Promise < Response > | Response | undefined {
3229 // no early return as esbuild would not treeshake the code.
3330 if ( __SKEW_PROTECTION_ENABLED__ ) {
3431 const url = new URL ( request . url ) ;
3532
3633 // Skew protection is only active for the latest version of the app served on a custom domain.
37- // For `localhost` and older deployments we still need to serve assets when the worker runs first.
3834 if ( url . hostname === "localhost" || url . pathname . endsWith ( ".workers.dev" ) ) {
39- return maybeFetchAsset ( request , assets ) ;
35+ return undefined ;
4036 }
4137
4238 const requestDeploymentId = request . headers . get ( "x-deployment-id" ) ?? url . searchParams . get ( "dpl" ) ;
4339
4440 if ( ! requestDeploymentId || requestDeploymentId === process . env . DEPLOYMENT_ID ) {
4541 // The request does not specify a deployment id or it is the current deployment id
46- return maybeFetchAsset ( request , assets ) ;
42+ return undefined ;
4743 }
4844
4945 const mapping = process . env [ DEPLOYMENT_MAPPING_ENV_NAME ]
@@ -69,69 +65,8 @@ export function maybeGetSkewProtectionResponse(
6965 }
7066}
7167
72- /**
73- * Fetches a file from the assets when the path is a known asset.
74- *
75- * @param request The incoming request
76- * @param assets The Fetcher used to retrieve assets
77- * @returns A `Promise<Response>` when the path is an assets, undefined otherwise
78- */
79- function maybeFetchAsset ( request : Request , assets : Fetcher | undefined ) : Promise < Response > | undefined {
80- if ( ! assets ) {
81- return undefined ;
82- }
83-
84- let path = new URL ( request . url ) . pathname ;
85- const basePath = globalThis . __NEXT_BASE_PATH__ ;
86- if ( basePath && path . startsWith ( basePath ) ) {
87- path = path . slice ( basePath . length ) ;
88- }
89- if ( path . startsWith ( "/_next/static/" ) || isFileInTree ( path , __CF_ASSETS_TREE__ ) ) {
90- return assets . fetch ( request ) ;
91- }
92- }
93-
94- /**
95- * A node represents a folder in the file tree
96- */
97- export type FolderNode = {
98- // List of files in this folder
99- f : string [ ] ;
100- // Sub-folders.
101- d : Record < string , FolderNode > ;
102- } ;
103-
104- /**
105- * Checks whether a file is in the tree
106- *
107- * @param filepath The path to the file
108- * @param tree The root node of the tree
109- * @returns Whether the file is in this tree
110- */
111- export function isFileInTree ( filepath : string , tree : FolderNode ) : boolean {
112- // Split the filename into components, filtering out empty strings from potential leading/trailing slashes
113- const parts = filepath . split ( "/" ) . filter ( Boolean ) ;
114-
115- if ( parts . length === 0 ) {
116- return false ; // An empty filename cannot be in the tree
117- }
118-
119- let currentNode : FolderNode | undefined = tree ;
120-
121- // Traverse through folder parts
122- for ( let i = 0 ; i < parts . length - 1 ; i ++ ) {
123- currentNode = currentNode . d [ parts [ i ] as string ] ;
124- if ( ! currentNode ) {
125- return false ; // Folder not found in the tree
126- }
127- }
128- // Check if the file exists in the current node's files array
129- return currentNode . f . includes ( parts . at ( - 1 ) as string ) ;
130- }
131-
13268/* eslint-disable no-var */
13369declare global {
13470 var __SKEW_PROTECTION_ENABLED__ : boolean ;
135- var __CF_ASSETS_TREE__ : FolderNode ;
13671}
13772/* eslint-enable no-var */
0 commit comments