Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

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
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