nuxt-community / proxy-module

The one-liner node.js http-proxy middleware solution for Nuxt 2 using http-proxy-middleware
MIT License
413 stars 26 forks source link

Use store value as header #30

Open yaki4 opened 5 years ago

yaki4 commented 5 years ago

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)
ghost commented 5 years ago

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.

ricardogobbosouza commented 5 years ago

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

mistricky commented 5 years ago

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.

atinux commented 3 years ago

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