Provide a way to opt-out middlewares from running at SSG #867
Replies: 5 comments 11 replies
-
@danielo515 please fill the template |
Beta Was this translation helpful? Give feedback.
-
Just found this. It is already possible to differentiate between those stages, but it is not intuitive if you are unfamiliar with Astro details (maybe even some internals). So, I just published that as an integration to make it easy to use: https://inox-tools.vercel.app/astro-when Specifically, you might want to look at the middleware example: https://github.com/Fryuni/inox-tools/blob/main/examples/astro-when/src/middleware.ts This is not to say that this won't be available as a higher-level API part of Astro, nor that it will. I'm just providing a wrapper on how it is already currently possible with the lower-level APIs. The integration above should continue to work even if Astro gets its own API for it. |
Beta Was this translation helpful? Give feedback.
-
Related - I've configured my (Astro 4.10.1) project with output mode server and my middleware.ts file code is checking context.request.headers. When I configure a specifc astro page with
|
Beta Was this translation helpful? Give feedback.
-
Yes, but the middleware running is the unexpected thing
El mar, 11 jun 2024, 15:42, Emanuele Stoppa ***@***.***>
escribió:
… That's expected. Prerendered pages will be built, and they will become
HTML pages, so it's expected that you won't have access to
Astro.request.headers.
—
Reply to this email directly, view it on GitHub
<#867 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AARKJWMNAW4GKVOUN635WBDZG35DJAVCNFSM6AAAAABE5B6FX6VHI2DSMVQWIX3LMV43SRDJONRXK43TNFXW4Q3PNVWWK3TUHM4TOMZZGUZTA>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
Just to be sure I understand, can someone explain me what is the use case
for a middleware running in static generation? They are inherently dynamic
to me
El mié, 12 jun 2024, 12:39, Emanuele Stoppa ***@***.***>
escribió:
… Oooh, I see! That makes sense now! I'll think about it
—
Reply to this email directly, view it on GitHub
<#867 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AARKJWMUBKMGMHRPFNWPA6LZHAQO5AVCNFSM6AAAAABE5B6FX6VHI2DSMVQWIX3LMV43SRDJONRXK43TNFXW4Q3PNVWWK3TUHM4TONJQGE3DE>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
Body
Here we go again...
Summary
I want to be able to opt out of middlewares running at build step (SSG phase)
Background & Motivation
I use middlewares to do both authentication and authorization, which does not make sense for static pages, so in the best case they are just overhead, and in the worst they prevent some pages from being properly rendered.
Goals
process.env.SSG
or something like that so I can decide in the middleware based on that.Example
Something like I already mentioned
import.meta.env.SSG
Beta Was this translation helpful? Give feedback.
All reactions