unjs / ipx

🖼️ High performance, secure and easy-to-use image optimizer.
MIT License
1.54k stars 61 forks source link

feat(options): add fetch option property for resource request #61

Closed ThornWalli closed 2 years ago

ThornWalli commented 2 years ago

I have the case that the resources are behind an OAuth and need to send an Authorization header with the fetch.

I added a new property fetchOptions to the options. This will be passed through to the fetch.

Usage example:

const ipx = createIPX({
  domains: […],
  aliases: {…},

  fetchOptions: {
    headers: {
      Authorization: 'Bearer …'
    }
  },

  // or function call for token handling

  fetchOptions: async () => {
    headers: {
      Authorization: await getToken()
    }
  }
});
pi0 commented 2 years ago

Thanks for PR @ThornWalli <3 Moved to #74