-
Notifications
You must be signed in to change notification settings - Fork 126
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Better support for cloudflare external middleware (#449)
* fix open-next config issue * handle next image in external middleware * make cache work with ISR/SSG * fix buffer issues head request * add host image loader * add comment * Create wicked-ligers-speak.md
- Loading branch information
Showing
16 changed files
with
201 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"open-next": patch | ||
--- | ||
|
||
Better support for cloudflare external middleware |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { Readable } from "node:stream"; | ||
import { ReadableStream } from "node:stream/web"; | ||
|
||
import { ImageLoader } from "types/open-next"; | ||
import { FatalError } from "utils/error"; | ||
|
||
const hostLoader: ImageLoader = { | ||
name: "host", | ||
load: async (key: string) => { | ||
const host = process.env.HOST; | ||
if (!host) { | ||
throw new FatalError("Host must be defined!"); | ||
} | ||
const url = `https://${host}${key}`; | ||
const response = await fetch(url); | ||
if (!response.ok) { | ||
throw new FatalError(`Failed to fetch image from ${url}`); | ||
} | ||
if (!response.body) { | ||
throw new FatalError("No body in response"); | ||
} | ||
const body = Readable.fromWeb(response.body as ReadableStream<Uint8Array>); | ||
const contentType = response.headers.get("content-type") ?? "image/jpeg"; | ||
const cacheControl = | ||
response.headers.get("cache-control") ?? | ||
"private, max-age=0, must-revalidate"; | ||
return { | ||
body, | ||
contentType, | ||
cacheControl, | ||
}; | ||
}, | ||
}; | ||
|
||
export default hostLoader; |
Oops, something went wrong.