nuxt / icon

The <Icon> component, supporting Iconify, Emojis and custom components.
https://stackblitz.com/edit/nuxt-icon-playground?file=app.vue
MIT License
961 stars 59 forks source link

Fix potential clash with /api #236

Closed Cheaterman closed 3 months ago

Cheaterman commented 3 months ago

The /api/* prefix is common enough that some people will want to use it for their own purposes, breaking NuxtIcon.

โ“ Type of change

๐Ÿ“š Description

Here I use the following code in my nuxt.config.ts which allows SSR to communicate with my (non-Nuxt) backend :

  nitro: {
    routeRules: {
      '/api/**': { proxy: 'http://proxy:80/api/**' },
    },
  },

Which breaks recent versions of NuxtIcon because it (boldly) assumes /api is available. This PR fixes that.

EDIT: I currently fix this by adding

  icon: {
    localApiEndpoint: '/_nuxt_icon_api/',
  },

to my nuxt.config.ts but I assume it shouldn't be necessary.

antfu commented 3 months ago

I don't think we should change the default, as the module does assume you have a Nuxt backend. In your case where you configure your custom backend, the module does offer you the option to configure it, as you already pointed out. I am not sure if we need to do anything here, consider your cases are also a bit specific.

Cheaterman commented 3 months ago

I do think considering /api/ namespace available is still a fairly bold assumption to make, even when someone is using a Nuxt backend ; people will usually want it for their own apps? As in, I don't agree that it's "a bit specific" to consider it unavailable.

Besides, I don't think it breaks anything to change the current default, while keeping it as-is evidently does break some setups, so I'm not sure what's the holdup here?

antfu commented 3 months ago

/api/ is the default convention Nuxt has. Whatever the name we choose, there is a chance to "clash" if you want to say it strictly. Instead of a random name like /_ prefixed, I'd prefer to follow Nuxt's default convention. It's not hard-coded, and you can change it to whatever makes sense to you.

Thanks for bringing this up.