Closed kireerik closed 11 months ago
My initial thought here is that integrations shouldn't add middleware internally since the user wouldn't be able to control the order that middlewares are executed - I'd expect users to always add middlewares directly even if the middleware itself is imported from an NPM package
@ematipico I'm curious if you have any thoughts on how Astro.locals
and middleware may work from inside of an integration while working on the RFC. Any ideas on if there's a safe way integrations could add middlewares?
There's a third-party PR that would allow an adapter to receive and manipulate the Astro.locals
: https://github.com/withastro/astro/pull/7049
But that's for adapters, not integrations.
The main issue I could see that we haven't managed to untangle is the ordering of the functions when creating the middleware.
The only solution I could see for integrations, is to expose a separate function that consumers can use inside the middleware.ts
file.
@kireerik that's not how you're supposed to use the Astro Middleware.
The middleware you use in your snippet, is the middleware provided by vite, which is totally unrelated to Astro Middleware.
@ematipico I see. I am looking for a way to pass a function
to a (static) Astro page endpoint from the referenced hook
. Is there a way to do that?
(Currently I am using the
global
object as a workaround.)
@ematipico I see. I am looking for a way to pass a
function
to a (static) Astro page endpoint from the referencedhook
. Is there a way to do that?(Currently I am using the
global
object as a workaround.)
Probably after merging this? https://github.com/withastro/astro/pull/7385
Otherwise, there isn't :(
withastro/astro#7385 was released recently. So now it is possible somehow?
I'm going to move this to our roadmap
repo so we can discuss this, since it'd be a new feature.
What version of
astro
are you using?2.5.5
Are you using an SSR adapter? If so, which one?
no
What package manager are you using?
pnpm
What operating system are you using?
Windows
What browser are you using?
Chrome
Describe the Bug
I have tried it like this:
astro.config.js
:But in the static file endpoint I am always getting an empty
locals
object ({}
): ((src/pages/
)index
).js
:Link to Minimal Reproducible Example
https://stackblitz.com/edit/github-z6jvzs?file=astro.config.js,src%2Fpages%2Findex.js
Participation