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

Allow . in Netlify edge function paths #1082

Merged
merged 2 commits into from
Oct 23, 2023
Merged

Conversation

iainmerrick
Copy link
Contributor

@iainmerrick iainmerrick commented Oct 6, 2023

PR Checklist

Please check if your PR fulfills the following requirements:

  • Tests for the changes have been added (for bug fixes / features)

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • infrastructure changes
  • Other... Please describe:

What is the current behavior?

When deploying as a Netlify edge function, it explicitly does not handle any paths containing a "." character.

These paths fall through to the default Netlify 404 page (not the project's own 404).

What is the new behavior?

All requests are handled by the edge function. If the project has its own 404 page, we don't ever see the default Netlify 404.

Other information

I've manually tested that this covers the following cases:

  • static asset (with or without . in name)
  • dynamic routes (with or without . in name)
  • internal fetch of static asset (from public)
  • internal fetch of dynamic route

If you'd like me to put together a test, let me know. It's not really specific to Netlify so I guess it doesn't belong in this package.

@iainmerrick
Copy link
Contributor Author

iainmerrick commented Oct 7, 2023

Now I see what's going on; edge functions shadow static assets, so with this PR as it stands all assets will be shadowed and served as 404s by the edge function instead. I didn't notice this at first because all the assets were cached, doh.

Skipping the edge function for paths containing . handles most common cases pretty well, but it blocks a lot of useful legitimate usage (for example, I'd like to implement the GOPROXY protocol which necessarily uses .).

I'll keep digging and see if I can figure out a better compromise.

@iainmerrick
Copy link
Contributor Author

I've added "excludedPath": "/assets/*" to the manifest, and that fixes the Vite assets.

Static files in public (e.g. favicon.ico) still don't work because they could live anywhere.

…unctions

1. Previously, all paths containing '.' we assumed to be static assets.
   - Now all paths are handled initially by our edge function. We manually call
     context.next() to see whether there's a matching static asset.

2. Previously, internal fetch() calls would only work for dynamic content.
   - We now normalize the URL and call Netlify's fetch() in all cases. Internal
     fetch() now works correctly for both static and dynamic content.
@iainmerrick
Copy link
Contributor Author

OK! This PR now covers all the following cases:

  • static asset (with or without . in name)
  • dynamic routes (with or without . in name)
  • internal fetch of static asset (from public)
  • internal fetch of dynamic route

If you'd like me to put together a test, let me know. It's not really specific to Netlify so I guess the test wouldn't belong in this package.

@ryansolid
Copy link
Member

I think the case I'd want to check is top level wildcard routes.. classically having star routes like we do in the Hackernews example break when we don't put some sort of criteria in.

@iainmerrick
Copy link
Contributor Author

iainmerrick commented Oct 19, 2023

I think the case I'd want to check is top level wildcard routes.. classically having star routes like we do in the Hackernews example break when we don't put some sort of criteria in.

Makes sense... I've deployed the HN sample using my solid-start-netlify branch here: iainmerrick/solid-start-edge-test#1

Looks like it's working correctly. I'll add a few routes to test those cases I listed.

(I tried running the main solid-start integration test with START_ADAPTER=solid-start-netlify but couldn't get it to work at all! There must be some trick I'm missing)

@ryansolid ryansolid merged commit c859766 into solidjs:main Oct 23, 2023
9 checks passed
@ryansolid
Copy link
Member

Seems good to me thanks for testing

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.

2 participants