question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Doesn't correctly proxy some requests (may involve Firebase)

See original GitHub issue

I’m developing a Firebase app using Webpack and the Webpack DevServer (which uses http-proxy-middleware). To load Firebase in the browser, I’m taking advantage of the reserved URLs that Firebase hosting provides. Of course, these URLs don’t work when DevServer is hosting my files, so I set up the proxy to redirect any requests to /__ to go to my Firebase hosting URL (https://[myapp].firebaseapp.com). It works for the library files (eg /__/firebase/4.2.0/firebase-app.js).

However, the proxy does not work for the init file (/__/firebase/init.js). That file returns a page like this:

image

However, directly visiting https://[myapp].firebaseapp.com/__/firebase/init.js DOES return the init file, as expected. I can also retrieve the file using Postman, so I don’t think it’s an issue with the useragent.

It seems to be some issue with the proxy.

Any ideas/solutions would be appreciated.

Setup

  • http-proxy-middleware: 0.17.4
  • server: webpack-dev-server 2.5.0
  • webpack: 3.0.0

proxy middleware configuration

// webpack config
{
  // webpack stuff
 //...

  devServer: {
    contentBase: './public',
    inline: true,
    stats: {
      colors: true
    },
    proxy: {
      '/__': {
        target: 'https://my-app.firebaseapp.com',
        secure: false // Without this, all requests fail
      }
    }
  }
}

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
chimuraicommented, Aug 31, 2017

It’s described in the documentation: https://github.com/chimurai/http-proxy-middleware

Firebase uses name-based virtual hosts; Basically they are reusing a single ip-address for multiple host names. The host header needs to be proxied correctly for name-based virtual hosts. Setting changeOrigin to true will fix the host header for you.

https://en.wikipedia.org/wiki/Virtual_hosting#Name-based

1reaction
chimuraicommented, Aug 31, 2017

Can you try adding this option: changeOrigin: true.

    proxy: {
      '/__': {
        target: 'https://my-app.firebaseapp.com',
        changeOrigin: true,
        secure: false // Without this, all requests fail
      }
    }
Read more comments on GitHub >

github_iconTop Results From Across the Web

Configure Hosting behavior | Firebase Hosting - Google
Firebase Hosting compares the source or regex value against all URL paths at the start of every request (before the browser determines whether...
Read more >
React-App Proxy isn't working in firebase production build
I am trying to dynamically load GLTF files stored in a Microsoft Azure Blob Storage into my react-three-fiber application via an url.
Read more >
Understanding APIs and API proxies | Apigee Edge
HTTP requests enter through the proxy request endpoint, are passed to the target request endpoint. How do you create an API proxy? An...
Read more >
What is Firebase? The complete story, abridged. - Medium
Because of the way Firebase products work, some people might call ... Firebase Hosting lets you proxy the request and response to and...
Read more >
[GA4] Firebase integration - Analytics Help - Google Support
Update settings after creating the link · Adjust the access level for Firebase users to Analytics data · Turn off enhanced audience integration...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found