Skip to content

Commit 9f12a7b

Browse files
committed
fix(cloudflare): remove Netlify runtime redirect lookup
1 parent 1597575 commit 9f12a7b

3 files changed

Lines changed: 25 additions & 19 deletions

File tree

helpers/astro/request.js

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { getNetlifyRedirect } from '~/helpers/config-node.js'
2-
1+
import { getRedirectRule } from '../../src/middleware-rules.js'
32

43
const ONE_SECOND = 1
54
const ONE_MINUTE = 60
@@ -55,21 +54,11 @@ export async function applyResponseDefaults ( Astro ) {
5554

5655
export async function catchRedirectResponse ( Astro ) {
5756
const requestUrl = new URL( Astro.request.url )
57+
const redirectRule = getRedirectRule( requestUrl.pathname )
5858

59-
let netlifyRedirectUrl = null
60-
61-
try {
62-
netlifyRedirectUrl = await getNetlifyRedirect( requestUrl.pathname )
63-
} catch ( error ) {
64-
console.warn( `Skipping redirect lookup for ${ requestUrl.pathname }`, error )
65-
}
66-
67-
// console.log('netlifyRedirectUrl', netlifyRedirectUrl)
68-
69-
if ( netlifyRedirectUrl !== null ) {
70-
return Astro.redirect( netlifyRedirectUrl.to )
59+
if ( redirectRule !== null ) {
60+
return Astro.redirect( redirectRule.to, redirectRule.status )
7161
}
7262

7363
return null
7464
}
75-

test/playwright/apple-silicon-app-test.playwright.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ describe( 'Apple Silicon app test page', () => {
4141
env: {
4242
TEST_RESULT_STORE: '/api/test-results'
4343
},
44-
preferConfiguredBaseUrl: false
44+
preferConfiguredBaseUrl: true
4545
})
4646

4747
browser = await launchBrowser()
@@ -78,7 +78,9 @@ describe( 'Apple Silicon app test page', () => {
7878
} )
7979

8080
await page.waitForFunction( () => {
81-
const island = document.querySelector( 'astro-island[component-url="/pages/apple-silicon-app-test.vue"]' )
81+
const island = [ ...document.querySelectorAll( 'astro-island' ) ].find( element => {
82+
return element.getAttribute( 'component-url' )?.includes( 'apple-silicon-app-test' )
83+
} )
8284

8385
return Boolean( island && !island.hasAttribute( 'ssr' ) )
8486
}, {
@@ -121,7 +123,7 @@ describe( 'Apple Silicon app test page', () => {
121123
} )
122124

123125
async function stubResultStore ( page: Page, submittedScans: Record<string, unknown>[] ) {
124-
await page.route( '**/api/test-results', async route => {
126+
await page.route( '**/api/test-results*', async route => {
125127
const postData = route.request().postDataJSON()
126128

127129
if ( postData && typeof postData === 'object' ) {

test/prebuild/middleware.test.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
import { describe, expect, it } from 'vitest'
1+
import { describe, expect, it, vi } from 'vitest'
22

3+
import { catchRedirectResponse } from '../../helpers/astro/request.js'
34
import {
45
getRedirectRule,
56
isProductionHostname
@@ -26,4 +27,18 @@ describe( 'site middleware', () => {
2627
expect( isProductionHostname( 'cf.doesitarm.com' ) ).toBe( false )
2728
expect( isProductionHostname( 'doesitarm-preview.workers.dev' ) ).toBe( false )
2829
} )
30+
31+
it( 'resolves redirects without reading Netlify runtime config', async () => {
32+
const redirect = vi.fn()
33+
34+
const response = await catchRedirectResponse({
35+
request: {
36+
url: 'https://doesitarm.com/app/electron'
37+
},
38+
redirect
39+
})
40+
41+
expect( response ).toBeUndefined()
42+
expect( redirect ).toHaveBeenCalledWith( '/app/electron-framework', 301 )
43+
} )
2944
} )

0 commit comments

Comments
 (0)