Skip to content

Commit ea0ab0c

Browse files
committed
Fix requesting public files returns 404
1 parent 58aaaed commit ea0ab0c

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

.changeset/short-masks-act.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"open-next": patch
3+
---
4+
5+
Fix requesting public files returns 404

packages/open-next/src/adapters/server-adapter.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -138,10 +138,7 @@ export async function handler(
138138
: eventParser.apiv2(event as APIGatewayProxyEventV2);
139139

140140
// WORKAROUND: public/ static files served by the server function (AWS specific) — https://github.com/serverless-stack/open-next#workaround-public-static-files-served-by-the-server-function-aws-specific
141-
if (
142-
publicAssets[parser.rawPath] === "file" ||
143-
publicAssets[parser.rawPath.split("/")[0]] === "dir"
144-
) {
141+
if (isPublicAsset(parser.rawPath)) {
145142
return isCloudFrontEvent
146143
? formatCloudFrontFailoverResponse(event as CloudFrontRequestEvent)
147144
: formatApiv2FailoverResponse();
@@ -206,6 +203,17 @@ function loadPublicAssets() {
206203
return JSON.parse(json) as PublicAssets;
207204
}
208205

206+
function isPublicAsset(rawPath: string) {
207+
console.log(publicAssets);
208+
console.log({ rawPath });
209+
// rawPath = "/favicon.ico"
210+
// rawPath = "/images/logo.png"
211+
return (
212+
publicAssets[rawPath] === "file" ||
213+
publicAssets[rawPath.split("/").slice(0, 2).join("/")] === "dir"
214+
);
215+
}
216+
209217
async function processRequest(req: IncomingMessage, res: ServerResponse) {
210218
// @ts-ignore
211219
// Next.js doesn't parse body if the property exists

0 commit comments

Comments
 (0)