@@ -17,8 +17,8 @@ import type {
1717import { build } from 'esbuild' ;
1818import { glob , globSync } from 'tinyglobby' ;
1919import { copyDependenciesToFunction } from './lib/nft.js' ;
20- import type { Args } from './ssr-function.js' ;
2120import { sessionDrivers } from 'astro/config' ;
21+ import { createConfigPlugin } from './vite-plugin-config.js' ;
2222
2323const { version : packageVersion } = JSON . parse (
2424 await readFile ( new URL ( '../package.json' , import . meta. url ) , 'utf8' ) ,
@@ -361,15 +361,17 @@ export default function netlifyIntegration(
361361 }
362362
363363 async function writeSSRFunction ( {
364- notFoundContent,
365364 logger,
366365 root,
366+ serverEntry,
367+ notFoundContent,
367368 } : {
368- notFoundContent ?: string ;
369369 logger : AstroIntegrationLogger ;
370370 root : URL ;
371+ serverEntry : string ;
372+ notFoundContent : string | undefined ;
371373 } ) {
372- const entry = new URL ( './entry.mjs' , ssrBuildDir ( ) ) ;
374+ const entry = new URL ( `./ ${ serverEntry } ` , ssrBuildDir ( ) ) ;
373375
374376 const _includeFiles = integrationConfig ?. includeFiles || [ ] ;
375377 const _excludeFiles = integrationConfig ?. excludeFiles || [ ] ;
@@ -412,27 +414,25 @@ export default function netlifyIntegration(
412414 await writeFile (
413415 new URL ( './ssr.mjs' , ssrOutputDir ( ) ) ,
414416 `
415- import createSSRHandler from './${ handler } ';
416- export default createSSRHandler(${ JSON . stringify ( {
417- cacheOnDemandPages : Boolean ( integrationConfig ?. cacheOnDemandPages ) ,
418- notFoundContent,
419- } ) } );
420- export const config = {
421- includedFiles: ['**/*'],
422- name: 'Astro SSR',
423- nodeBundler: 'none',
424- generator: '@astrojs/netlify@${ packageVersion } ',
425- path: '/*',
426- preferStatic: true,
427- };
428- ` ,
417+ import { config, createHandler } from './${ handler } ';
418+
419+ export default createHandler(${ JSON . stringify ( { notFoundContent } ) } );
420+
421+ export { config };
422+ ` ,
429423 ) ;
430424 }
431425
432- async function writeMiddleware ( entrypoint : URL ) {
426+ async function writeMiddleware ( {
427+ entrypoint,
428+ serverEntry,
429+ } : {
430+ entrypoint : URL ;
431+ serverEntry : string ;
432+ } ) {
433433 await mkdir ( middlewareOutputDir ( ) , { recursive : true } ) ;
434434 await writeFile (
435- new URL ( './entry.mjs' , middlewareOutputDir ( ) ) ,
435+ new URL ( `./ ${ serverEntry } ` , middlewareOutputDir ( ) ) ,
436436 /* ts */ `
437437 import { onRequest } from "${ fileURLToPath ( entrypoint ) . replaceAll ( '\\' , '/' ) } ";
438438 import { createContext, trySerializeLocals } from 'astro/middleware';
@@ -482,7 +482,7 @@ export default function netlifyIntegration(
482482
483483 // taking over bundling, because Netlify bundling trips over NPM modules
484484 await build ( {
485- entryPoints : [ fileURLToPath ( new URL ( './entry.mjs' , middlewareOutputDir ( ) ) ) ] ,
485+ entryPoints : [ fileURLToPath ( new URL ( `./ ${ serverEntry } ` , middlewareOutputDir ( ) ) ) ] ,
486486 // allow `node:` prefixed imports, which are valid in netlify's deno edge runtime
487487 plugins : [
488488 {
@@ -638,15 +638,28 @@ export default function netlifyIntegration(
638638 redirects : false ,
639639 client : outDir ,
640640 server : ssrBuildDir ( ) ,
641+ serverEntry : 'ssr-function.mjs' ,
641642 } ,
642643 session,
643644 vite : {
644- plugins : [ netlifyVitePlugin ( vitePluginOptions ) ] ,
645+ plugins : [
646+ netlifyVitePlugin ( vitePluginOptions ) ,
647+ createConfigPlugin ( {
648+ middlewareSecret,
649+ cacheOnDemandPages : ! ! integrationConfig ?. cacheOnDemandPages ,
650+ packageVersion,
651+ } ) ,
652+ ] ,
645653 server : {
646654 watch : {
647655 ignored : [ fileURLToPath ( new URL ( './.netlify/**' , rootDir ) ) ] ,
648656 } ,
649657 } ,
658+ build : {
659+ rollupOptions : {
660+ input : '@astrojs/netlify/ssr-function.js' ,
661+ } ,
662+ } ,
650663 } ,
651664 image : {
652665 service : {
@@ -675,13 +688,11 @@ export default function netlifyIntegration(
675688
676689 setAdapter ( {
677690 name : '@astrojs/netlify' ,
678- serverEntrypoint : '@astrojs/netlify/ssr-function.js' ,
679- exports : [ 'default' ] ,
691+ entryType : 'self' ,
680692 adapterFeatures : {
681693 edgeMiddleware : useEdgeMiddleware ,
682694 staticHeaders : useStaticHeaders ,
683695 } ,
684- args : { middlewareSecret } satisfies Args ,
685696 supportedAstroFeatures : {
686697 hybridOutput : 'stable' ,
687698 staticOutput : 'stable' ,
@@ -718,11 +729,19 @@ export default function netlifyIntegration(
718729 try {
719730 notFoundContent = await readFile ( new URL ( './404.html' , dir ) , 'utf8' ) ;
720731 } catch { }
721- await writeSSRFunction ( { notFoundContent, logger, root : _config . root } ) ;
732+ await writeSSRFunction ( {
733+ logger,
734+ root : _config . root ,
735+ serverEntry : _config . build . serverEntry ,
736+ notFoundContent,
737+ } ) ;
722738 logger . info ( 'Generated SSR Function' ) ;
723739 }
724740 if ( astroMiddlewareEntryPoint ) {
725- await writeMiddleware ( astroMiddlewareEntryPoint ) ;
741+ await writeMiddleware ( {
742+ entrypoint : astroMiddlewareEntryPoint ,
743+ serverEntry : _config . build . serverEntry ,
744+ } ) ;
726745 logger . info ( 'Generated Middleware Edge Function' ) ;
727746 }
728747
0 commit comments