-
Notifications
You must be signed in to change notification settings - Fork 67
initial support for next/image on netlify #138
Conversation
const quality = parseInt(q); | ||
|
||
const imageUrl = url.startsWith("/") | ||
? `${process.env.URL || "http://localhost:8888"}${url}` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure about this ||, but i think it's fine since ntl dev uses 8888 as its default port right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is probably okay in the short term, but the port is configurable. quick fix is the create a .env
with URL=http://localhost:5432
or whatever to override locally
|
||
// Function used to mimic next/image and sharp | ||
exports.handler = async (event) => { | ||
const { url, w = 500, q = 75 } = event.queryStringParameters; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure about these defaults but i think it's fine since next_image should almost always provide w
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we probably want some reasonable default just in case so we don't end up trying to process 6MB images at full res or whatever, but I think you're right that it should always be set
Co-authored-by: Jason Lengstorf <[email protected]>
Fixes #70
as this comment points out, this solution for initial support is not performant because the function will re-run on every request without any caching. that said, this PR is just initial support. we have performance improvements on our roadmap, depending on internal work at netlify. this PR adds this caveat to our README.
my plan, once this PR is merged, is to close #70, open a new issue that addresses performance, and update #70 so anyone from there can follow the new issue.
s/o to @jlengstorf for doing the 90% of work ahead of this PR 🙏