{"record":{"id":"6de4a1a4166f1e2e","repo":"withastro/astro","slug":"please-use-astro-url-instead","errorCode":null,"errorMessage":"Please use Astro.url instead.","messagePattern":"Please use Astro\\.url instead\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/integrations/netlify/src/index.ts","lineNumber":556,"sourceCode":"\t\t\t\t// Import Deno polyfill for `process.env` at the top of the file\n\t\t\t\tjs: 'import process from \"node:process\";',\n\t\t\t},\n\t\t});\n\t}\n\n\tfunction getLocalDevNetlifyContext(req: IncomingMessage): Context {\n\t\tconst isHttps = req.headers['x-forwarded-proto'] === 'https';\n\t\tconst parseBase64JSON = <T = unknown>(header: string): T | undefined => {\n\t\t\tif (typeof req.headers[header] === 'string') {\n\t\t\t\ttry {\n\t\t\t\t\treturn JSON.parse(Buffer.from(req.headers[header] as string, 'base64').toString('utf8'));\n\t\t\t\t} catch {}\n\t\t\t}\n\t\t};\n\n\t\tconst context: Context = {\n\t\t\tget url(): never {\n\t\t\t\tthrow new Error('Please use Astro.url instead.');\n\t\t\t},\n\t\t\t// The dev server is a long running process, so promises will run even with a noop\n\t\t\twaitUntil: () => {},\n\t\t\taccount: parseBase64JSON('x-nf-account-info') ?? {\n\t\t\t\tid: 'mock-netlify-account-id',\n\t\t\t},\n\t\t\tdeploy: {\n\t\t\t\tcontext: 'dev',\n\t\t\t\tid:\n\t\t\t\t\ttypeof req.headers['x-nf-deploy-id'] === 'string'\n\t\t\t\t\t\t? req.headers['x-nf-deploy-id']\n\t\t\t\t\t\t: 'mock-netlify-deploy-id',\n\t\t\t\tpublished: false,\n\t\t\t},\n\t\t\tsite: parseBase64JSON('x-nf-site-info') ?? {\n\t\t\t\tid: 'mock-netlify-site-id',\n\t\t\t\tname: 'mock-netlify-site.netlify.app',\n\t\t\t\turl: `${isHttps ? 'https' : 'http'}://localhost:${isRunningInNetlify ? 8888 : 4321}`,","sourceCodeStart":538,"sourceCodeEnd":574,"githubUrl":"https://github.com/withastro/astro/blob/3578d45d34226d63cff3d261c971c221de6794d2/packages/integrations/netlify/src/index.ts#L538-L574","documentation":"In local development the Netlify adapter fabricates a mock Netlify Context for each request (getLocalDevNetlifyContext). Its url property is a getter that always throws: in Astro the request URL is exposed as Astro.url, and the stub exists to fail fast when Netlify Functions code reads context.url inside the Astro dev server.","triggerScenarios":"Reading locals.runtime.context.url (or destructuring { url } from the Netlify Context) in a page, endpoint, or middleware while running astro dev / netlify dev with the Netlify adapter.","commonSituations":"Copy-pasted Netlify Functions code where context.url is idiomatic; shared libraries that feature-detect context.url by touching it; code that works in a deployed function but is exercised locally for the first time.","solutions":["Use Astro.url (or Astro.request.url / context.request.url in middleware) instead of context.url","If you must keep Netlify-specific code, wrap the access in try/catch with an Astro.url fallback","Reserve context usage for fields Astro does not mirror (waitUntil, site, deploy) and read URL-like data from Astro APIs"],"exampleFix":"// before\nconst url = locals.runtime.context.url;\n// after\nconst url = Astro.url;","handlingStrategy":"fallback","validationCode":"// Before reading the Netlify Context in shared code, branch on the dev context:\nconst ctx = locals.runtime?.context;\nconst isLocalDev = ctx?.deploy?.context === 'dev';\nconst url = isLocalDev ? Astro.url : ctx!.url; // dev stub throws; prod context is real","typeGuard":"function safeNetlifyUrl(context: any, fallback: URL): URL {\n  try {\n    return context.url;\n  } catch {\n    return fallback;\n  }\n}","tryCatchPattern":"let url: URL;\ntry {\n  url = locals.runtime.context.url;\n} catch {\n  url = Astro.url; // local-dev stub always throws\n}","preventionTips":["Use Astro.url everywhere in Astro components; it works in dev and prod","Restrict Netlify Context reads to fields Astro does not mirror (waitUntil, site, deploy)","Exercise Netlify-specific helpers under astro dev before deploying"],"tags":["netlify","local-dev","context","url"],"backgroundTag":"unsupported-api-stub","analyzedSha":"3578d45d34226d63cff3d261c971c221de6794d2","analyzedAt":"2026-08-18T18:48:03.901Z","contentChangedAt":"2026-08-18T18:48:03.901Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}