@@ -85,7 +85,7 @@ export default createRequestHandler({
8585
8686// This is written to the edge functions directory. It just re-exports
8787// the compiled entrypoint, along with the Netlify function config.
88- function generateEdgeFunction ( handlerPath : string , exclude : Array < string > = [ ] ) {
88+ function generateEdgeFunction ( handlerPath : string , excludedPath : Array < string > ) {
8989 return /* js */ `
9090 export { default } from "${ handlerPath } ";
9191
@@ -94,7 +94,7 @@ function generateEdgeFunction(handlerPath: string, exclude: Array<string> = [])
9494 generator: "${ name } @${ version } ",
9595 cache: "manual",
9696 path: "/*",
97- excludedPath: ${ JSON . stringify ( exclude ) } ,
97+ excludedPath: ${ JSON . stringify ( excludedPath ) } ,
9898 };`
9999}
100100
@@ -125,7 +125,21 @@ const getEdgeFunctionHandlerModuleId = async (root: string, isHydrogenSite: bool
125125 return findUserEdgeFunctionHandlerFile ( root )
126126}
127127
128- export function netlifyPlugin ( ) : Plugin {
128+ export interface NetlifyPluginOptions {
129+ /**
130+ * Paths to exclude from being handled by the Remix handler.
131+ *
132+ * @IMPORTANT If you have your own Netlify Functions running on custom `path`s, you
133+ * must exclude those paths here to avoid conflicts.
134+ *
135+ * @type {string[] }
136+ * @default []
137+ */
138+ excludedPaths ?: string [ ]
139+ }
140+
141+ export function netlifyPlugin ( options : NetlifyPluginOptions = { } ) : Plugin {
142+ const additionalExcludedPaths = options . excludedPaths ?? [ ]
129143 let resolvedConfig : ResolvedConfig
130144 let currentCommand : string
131145 let isSsr : boolean | undefined
@@ -264,23 +278,25 @@ export function netlifyPlugin(): Plugin {
264278 async writeBundle ( ) {
265279 // Write the server entrypoint to the Netlify functions directory
266280 if ( currentCommand === 'build' && isSsr ) {
267- const exclude : Array < string > = [ '/.netlify/*' ]
281+ const excludedPath : Array < string > = [ '/.netlify/*' ]
268282 try {
269283 // Get the client files so we can skip them in the edge function
270284 const clientDirectory = join ( resolvedConfig . build . outDir , '..' , 'client' )
271285 const entries = await readdir ( clientDirectory , { withFileTypes : true } )
272286 for ( const entry of entries ) {
273287 // With directories we don't bother to recurse into it and just skip the whole thing.
274288 if ( entry . isDirectory ( ) ) {
275- exclude . push ( `/${ entry . name } /*` )
289+ excludedPath . push ( `/${ entry . name } /*` )
276290 } else if ( entry . isFile ( ) ) {
277- exclude . push ( `/${ entry . name } ` )
291+ excludedPath . push ( `/${ entry . name } ` )
278292 }
279293 }
280294 } catch {
281295 // Ignore if it doesn't exist
282296 }
283297
298+ excludedPath . push ( ...additionalExcludedPaths )
299+
284300 const edgeFunctionsDirectory = join ( resolvedConfig . root , NETLIFY_EDGE_FUNCTIONS_DIR )
285301
286302 await mkdir ( edgeFunctionsDirectory , { recursive : true } )
@@ -290,7 +306,7 @@ export function netlifyPlugin(): Plugin {
290306
291307 await writeFile (
292308 join ( edgeFunctionsDirectory , EDGE_FUNCTION_FILENAME ) ,
293- generateEdgeFunction ( relativeHandlerPath , exclude ) ,
309+ generateEdgeFunction ( relativeHandlerPath , excludedPath ) ,
294310 )
295311 }
296312 } ,
0 commit comments