Replies: 11 comments 14 replies
-
That was one of the workarounds that didn’t work when trying to make an i18n integration with It could make implementing a |
Beta Was this translation helpful? Give feedback.
-
I've published an alpha version of my html-to-image middleware generator for Astro. Here is what it looks like: I think this is really awesome, but it only works in SSR: it won't work in SSG until this issue is resolved. As such, I'm going to leave my plugin in Alpha with a warning at the top until this is fixed. @natemoo-re / @matthewp please let me know if there's anything I can do to make it more likely for this to get done. Thanks! |
Beta Was this translation helpful? Give feedback.
-
I've published an alpha version of my opengraph-image middleware generator for Astro. Here is what it looks like: Same deal as the other middleware: it only works in SSR: it won't work in SSG until this issue is resolved. |
Beta Was this translation helpful? Give feedback.
-
I'm not sure about automatically inferring the file extension from headers. const response = new Response(body, {
headers: {
"Content-Type": "image/png", // Would be ignored during an SSG build
"Content-Disposition": `inline; filename="opengraph-image.png`,
},
})
// Would be ignored by the live server render
response[Symbol.for("astro.staticOutput.fileName")] = "opengraph-image.png"
// alternatively...
response[Symbol.for("astro.staticOutput.extension")] = "png"
return response The symbols would have no effect for SSR as suggested by the naming. |
Beta Was this translation helpful? Give feedback.
-
Hey everyone. I've created a codesandbox that shows off this integration with Astro v4. The integration now:
As with before, the feature requested in this discussion is still in the way of making this integration with in SSG mode. But I'm of the opinion that Astro v4 makes this integration even cooler and I humbly re-request help making it a reality. Thanks! |
Beta Was this translation helpful? Give feedback.
-
I think this is an important piece of information that is missing from your proposal. Can you tell us how browsers use these headers? Especially the |
Beta Was this translation helpful? Give feedback.
-
I ran into this usecase yesterday (well, only because I was using a middleware to work around not being able to render Markdoc with our renderer inside an API endpoint, but still), would like this feature |
Beta Was this translation helpful? Give feedback.
-
Just closed my issue on this that was similar. Would really love to see this as a feature. |
Beta Was this translation helpful? Give feedback.
-
I don't quite like the breaking symmetry between SSR and SSG that this causes. On SSR, you'd be accessing one URL, like On SSG, you'd be writing a
|
Beta Was this translation helpful? Give feedback.
-
I have run into this problem as well, however this conversation appears to have stalled over (important) implantation details. The end goal however of a middle ware or template (such as .astro) being able return a different header type opens a lot of possibilities, which appears to be the desired end goal. #881 expresses this goal succinctly, but has been closed in favour of this thread. Image generators are but one possible result, but an interesting one which would benefit from this sort of API. |
Beta Was this translation helpful? Give feedback.
-
I've put up a PR to implement this idea: withastro/astro#13024 |
Beta Was this translation helpful? Give feedback.
-
Body
Summary
Allow middleware to return a response for a different file than the current request. Currently middleware can only return a response for the requested document, e.g.
pages/home.astro
will always be written tohome/index.html
.Background & Motivation
Having this would enable me to make a much better opengraph image integration than what currently exists. Once my integration is installed, an
opengraph-image.astro
component would be served (or built, in SSG) as a PNG image instead of HTML.More detail: the middleware powering said integration would be a trivial gluing together of existing pieces: html response => VNODE (using @natemoo-re's satori-html) => svg (using Satori) => png (using sharp) =>
Response
. Configuration removed it's just a few lines of code. The only piece missing is that once the PNGResponse
is generated, the Astro middleware currently writes it toopengraph-image/index.html
instead of a PNG file.Goals
Response
headers likeContent-Type
andContent-Disposition
more like how a browser handles them. Specifically:Response
with aContent-Type
header. This will get passed-through in SSR mode.Content-Disposition
header that specifies a different filename. If this is specified in theResponse
then the file written will reflect the specified name instead of the default. This should work in SSR and SSG mode.Example
if this is returned by the middleware when requesting
opengraph-image.astro
:Content-Type: image/png
opengraph-image.png
filenameContent-Type: text/html
Content-Type: image/png
opengraph-image/index.html
opengraph-image.png
EDIT: SSR already works as described. So the only thing left to do is make SSG write to the
Content-Disposition
filename.Beta Was this translation helpful? Give feedback.
All reactions