(
path: string,
options?: RequestInit,
maxRedirects: number = 5,
)
| 76 | return res.status >= 300 && res.status < 400 && res.headers.get('location') |
| 77 | } |
| 78 | async function localFetch( |
| 79 | path: string, |
| 80 | options?: RequestInit, |
| 81 | maxRedirects: number = 5, |
| 82 | ): Promise<Response> { |
| 83 | const url = new URL(path, baseUrl) |
| 84 | const request = new Request(url, options) |
| 85 | const response = await fetch(request) |
| 86 | |
| 87 | if (isRedirectResponse(response) && maxRedirects > 0) { |
| 88 | const location = response.headers.get('location')! |
| 89 | if (location.startsWith('http://localhost') || location.startsWith('/')) { |
| 90 | const newUrl = location.replace('http://localhost', '') |
| 91 | return localFetch(newUrl, options, maxRedirects - 1) |
| 92 | } else { |
| 93 | logger.warn(`Skipping redirect to external location: ${location}`) |
| 94 | } |
| 95 | } |
| 96 | |
| 97 | return response |
| 98 | } |
| 99 | |
| 100 | try { |
| 101 | // Crawl all pages |
no test coverage detected