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

Match paths ending in a value (such as /**/*.png) #68

Closed
1 task
KyleSmith0905 opened this issue Oct 27, 2023 · 6 comments
Closed
1 task

Match paths ending in a value (such as /**/*.png) #68

KyleSmith0905 opened this issue Oct 27, 2023 · 6 comments

Comments

@KyleSmith0905
Copy link

Describe the feature

Context:

I'm trying to add the Cross-Origin-Resource-Policy on dynamically generated OG Images.

I haven't seen anything on Radix3's or Nitro's documentation, I've tested these regardless:

/__og_image__/og.png # Only gives the header on the homepage's og image.
/*/__og_image__/og.png # Does not provide the header on double nested pages.
/**/__og_image__/og.png # Does not provide the header on any page

Concerns:

I'm wondering if this would be possible as a feature since Radix3 is based on the radix tree? Though, you do support foo/*/bar, so idk.

Feature Request:

Add

/**/__og_image__/og.png

or if the feature already exist, add it to the documentation.

Willing To Help

I took a look at the code, and it was clean and easy to follow! However I don't have nearly enough knowledge on how this would be done. I'm willing to test the waters, but I don't think I'd be successful. :D

Additional information

  • Would you be willing to help implement this feature?
@dargmuesli
Copy link

@harlan-zw and I are interested in that as well! 😍

@pi0
Copy link
Member

pi0 commented Oct 29, 2023

This feature is planned in next major version and already implemented see #52

@harlan-zw
Copy link
Contributor

harlan-zw commented Oct 29, 2023

This feature is planned in next major version and already implemented see #52

Thanks for the detail, maybe you could help me understand this better. I looked at this code and I can't exactly see how this would work.

The first node needs to be an nth-deeply nested wildcard match.

For example, we need (ideally) a single route rule that will match ALL of the following:

  • /blog/nuxt-3-migration-cheatsheet/__og_image__/og.png
  • /blog/__og_image__/og.png
  • /__og_image__/og.png
  • /some/very/long/url/that/does/not/exist/but/this/is/an/example/__og_image__/og.png

I played with the latest code and this appears to be the output. Maybe I'm using it wrong though.

it('ends with pattern', () => {
    const router = createRouter({
      routes: {
        "/**/__og_image__/og.png": { m: "**/something/foo.png", order: 1 },
      },
    });
    const matcher = toRouteMatcher(router);
    const matches = matcher.matchAll("/my-path/__og_image__/og.png");
    expect(matches).toMatchInlineSnapshot('[]')
  })

If it is indeed possible with this PR, are you able to provide some code (or point in the right direction) and I can write some unit tests around it for the above?

@pi0
Copy link
Member

pi0 commented Oct 29, 2023

You cannot combine wildcard with following static marcher. For that you need /** matcher + h3 custom route matcher (with regex) or for Nuxt renderer, you can integrate with renderer hooks just like what we do for payload paths.

This is by design for sake of API simplicity/compatiblity in radix3.

Feel free to raise a new issue in h3 or nitro if you need an example of how to do this.

@harlan-zw
Copy link
Contributor

harlan-zw commented Oct 29, 2023

Yes, this is what I figured.

Afaik there isn't a way to handle it without using a Nitro / h3 middleware? See nuxt-modules/og-image#101 for context.

If that's the case, we can consider closing this issue.

@pi0
Copy link
Member

pi0 commented Mar 8, 2024

  • Mixed pattern /*.png coming with v2 (tracker v2 roadmap #88)
  • Wildcard /** can be only last segment

@pi0 pi0 closed this as not planned Won't fix, can't repro, duplicate, stale Mar 8, 2024
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

No branches or pull requests

4 participants