Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle assets-path correctly #362

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open

Handle assets-path correctly #362

wants to merge 3 commits into from

Conversation

fraxachun
Copy link
Contributor

If an assets-path to a file that does not exist in the public-folder is called (e.g. /assets/foo) then next tries to render this request and routes to page.tsx. The problem is that the rewrites in the middleware are not executed and "assets" is used as domain-parameter leading to a 500 (instead a desired 404).

This PR handles the assets-path and gets the site-config via the headers so that the 404-page can be rendered.

@nsams
Copy link
Member

nsams commented Sep 17, 2024

couldn't you instead avoid the 500 by returning null (instead of throwing Error) and call notFound() in page.tsx if getSiteConfigForDomain returned null?

@fraxachun
Copy link
Contributor Author

couldn't you instead avoid the 500 by returning null (instead of throwing Error) and call notFound() in page.tsx if getSiteConfigForDomain returned null?

This does not solve the root cause. We normally get the domain from the host (in the middleware) and use it later as domain param. So we can rely on the param to be correct. However, in this special case we skip the middleware so that we have to execute host matching code on a later stage.

Additionally, getSiteConfigForDomain is widely used, allowing to return null requires the consuming part to handle this case. Moreover, when rendering the not-found.tsx we also want to render the according layout.tsx files which themselves use this call.

Copy link
Collaborator

@johnnyomair johnnyomair left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's odd that this needs to be done in getSiteConfigForDomain, but I can't think of a better solution. We could try to get rid of the assets folder altogether, as we discussed in #283 (comment).

@@ -9,7 +9,13 @@ export function getHostByHeaders(headers: Headers) {
}

export function getSiteConfigForDomain(domain: string) {
const siteConfig = getSiteConfigs().find((siteConfig) => siteConfig.scope.domain === domain);
let siteConfig;
if (domain === "assets") {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should add a comment here explaining why this if is needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants