Skip to content

fix(plugins/fs_routes): error when exporting middleware array with createDefine().middleware#2799

Closed
nnmrts wants to merge 0 commit intodenoland:mainfrom
nnmrts:main
Closed

fix(plugins/fs_routes): error when exporting middleware array with createDefine().middleware#2799
nnmrts wants to merge 0 commit intodenoland:mainfrom
nnmrts:main

Conversation

@nnmrts
Copy link

@nnmrts nnmrts commented Dec 23, 2024

According to the docs of createDefine().middleware, it accepts a single function or an array of functions. But if you actually default export something like this:

export default createDefine().middleware([
  (context) => context.next(),
  (context) => context.next()
]);

you get this error:

error: Uncaught (in promise) Error: Expected a route, middleware, layout or error template, but couldn't find relevant exports in: _middleware.js
        throw new Error(
              ^
    at https://jsr.io/@fresh/core/2.0.0-alpha.27/src/plugins/fs_routes/mod.ts:127:15
    at async Promise.all (index 4)
    at async fsRoutes (https://jsr.io/@fresh/core/2.0.0-alpha.27/src/plugins/fs_routes/mod.ts:123:48)

For this reason, I updated the isFreshFile function to also allow a non empty array of functions. I also added tests and updated types surrounding it, unfortunately this led to a lot of lines in src/plugins/fs_routes/mod_test.tsx type-erroring "Parameter 'ctx' implicitly has an 'any' type", but I was unable to fix that with my little TS knowledge.

@nnmrts nnmrts changed the title Fix error when exporting middleware array with createDefine().middleware fix(plugins/fs_routes): error when exporting middleware array with createDefine().middleware Dec 23, 2024
@nnmrts nnmrts closed this Jul 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant