@@ -5,7 +5,13 @@ import { fileURLToPath } from 'node:url';
5
5
import { emptyDir } from '@astrojs/internal-helpers/fs' ;
6
6
import { createRedirectsFromAstroRoutes } from '@astrojs/underscore-redirects' ;
7
7
import type { Context } from '@netlify/functions' ;
8
- import type { AstroConfig , AstroIntegration , AstroIntegrationLogger , RouteData } from 'astro' ;
8
+ import type {
9
+ AstroConfig ,
10
+ AstroIntegration ,
11
+ AstroIntegrationLogger ,
12
+ HookParameters ,
13
+ RouteData ,
14
+ } from 'astro' ;
9
15
import { build } from 'esbuild' ;
10
16
import { copyDependenciesToFunction } from './lib/nft.js' ;
11
17
import type { Args } from './ssr-function.js' ;
@@ -201,6 +207,8 @@ export default function netlifyIntegration(
201
207
// Secret used to verify that the caller is the astro-generated edge middleware and not a third-party
202
208
const middlewareSecret = randomUUID ( ) ;
203
209
210
+ let finalBuildOutput : HookParameters < 'astro:config:done' > [ 'buildOutput' ] ;
211
+
204
212
const TRACE_CACHE = { } ;
205
213
206
214
const ssrBuildDir = ( ) => new URL ( './.netlify/build/' , rootDir ) ;
@@ -215,7 +223,7 @@ export default function netlifyIntegration(
215
223
] ) ;
216
224
217
225
async function writeRedirects ( routes : RouteData [ ] , dir : URL ) {
218
- const fallback = _config . output === 'static' ? '/.netlify/static' : '/.netlify/functions/ssr' ;
226
+ const fallback = finalBuildOutput === 'static' ? '/.netlify/static' : '/.netlify/functions/ssr' ;
219
227
const redirects = createRedirectsFromAstroRoutes ( {
220
228
config : _config ,
221
229
dir,
@@ -283,7 +291,7 @@ export default function netlifyIntegration(
283
291
import { createContext, trySerializeLocals } from 'astro/middleware';
284
292
285
293
export default async (request, context) => {
286
- const ctx = createContext({
294
+ const ctx = createContext({
287
295
request,
288
296
params: {}
289
297
});
@@ -294,7 +302,7 @@ export default function netlifyIntegration(
294
302
request.headers.set("x-astro-middleware-secret", "${ middlewareSecret } ");
295
303
return context.next();
296
304
};
297
-
305
+
298
306
return onRequest(ctx, next);
299
307
}
300
308
@@ -440,10 +448,12 @@ export default function netlifyIntegration(
440
448
} ,
441
449
} ) ;
442
450
} ,
443
- 'astro:config:done' : async ( { config, setAdapter, logger } ) => {
451
+ 'astro:config:done' : async ( { config, setAdapter, logger, buildOutput } ) => {
444
452
rootDir = config . root ;
445
453
_config = config ;
446
454
455
+ finalBuildOutput = buildOutput ;
456
+
447
457
await writeNetlifyFrameworkConfig ( config , logger ) ;
448
458
449
459
const edgeMiddleware = integrationConfig ?. edgeMiddleware ?? false ;
@@ -477,7 +487,7 @@ export default function netlifyIntegration(
477
487
await writeRedirects ( routes , dir ) ;
478
488
logger . info ( 'Emitted _redirects' ) ;
479
489
480
- if ( _config . output !== 'static' ) {
490
+ if ( finalBuildOutput !== 'static' ) {
481
491
let notFoundContent = undefined ;
482
492
try {
483
493
notFoundContent = await readFile ( new URL ( './404.html' , dir ) , 'utf8' ) ;
0 commit comments