proxy-module icon indicating copy to clipboard operation
proxy-module copied to clipboard

Use store value as header

Open yaki4 opened this issue 6 years ago • 4 comments

Hi i would like to use a store value with onProxyReq. But it seems that nuxt context or store is unavailable in proxy. Any ideas how to do it ? I've tried req.body but it's undefined. proxy: { '/graphql': { target: 'https://beautifulapigraph.com', onProxyReq: function (proxyReq, req, res, options) { proxyReq.setHeader('X-VAL', storeBasedValue) } } },

This question is available on Nuxt community (#c19)

yaki4 avatar Feb 18 '19 19:02 yaki4

This issue as been imported as question since it does not respect proxy-module issue template. Only bug reports and feature requests stays open to reduce maintainers workload. If your issue is not a question, please mention the repo admin or moderator to change its type and it will be re-opened automatically. Your question is available at https://cmty.app/nuxt/proxy-module/issues/c19.

ghost avatar Feb 18 '19 19:02 ghost

@yaki4 Do not have access to the store here, you can take a look here https://github.com/nuxt/nuxt.js/issues/2005

ricardogobbosouza avatar Mar 23 '19 13:03 ricardogobbosouza

Hi! I have a problem, It's about onProxyReq, It does not work when I set the custom header on request;

this is my nuxt config

  proxy: {
    '/proxy': {
      target: 'http://localhost:3000',
      pathRewrite: { '^/proxy/': '' },
      onProxyReq(proxyReq) {
        proxyReq.setHeader('X-Syl-Client-Token', 'foo')
      },
    },
  },

I can't see it in Network in Chrome.

mistricky avatar Oct 23 '19 07:10 mistricky

Could you please create a reproduction by using https://template.nuxtjs.org?

atinux avatar Jan 29 '21 11:01 atinux