Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Proxying external API for Firebase Hosting?

We created static one page WEB application that uses external API for authentication and data.

We set dedicated URL space prefixed with /api to solve cross domain restrictions with reverse proxy. Proxying works fine with Ngnix, Apache on local setup but I can't find proxying support in Firebase Hosting: https://firebase.google.com/docs/hosting/url-redirects-rewrites

There is Function offer that can run node runtime up to 1 minute per call. Can't it be used to implements reverse proxy?

UPDATE We ended with Heroku offering. It hosts our static JS/CSS assets via WEB server (internal detail of a particular cloud provider) and same WEB server is user for proxing API calls via defined extension point, mapped to URL root like /api.

This way JS application is written to issue API calls to URL without schema / host / port, it doesn't matter if you run it on localhost (development) or in cloud env (prod)!

like image 346
gavenkoa Avatar asked Mar 18 '26 21:03

gavenkoa


1 Answers

There's an excellent way to have Firebase Hosting as a proxy for specific functions: https://firebase.google.com/docs/hosting/full-config#rewrite-functions

That way, you can direct a specific route directly to one of your functions:

"hosting": {
  // ...

  // Directs all requests from the page `/bigben` to execute the `bigben` function
  "rewrites": [ {
    "source": "/bigben",
    "function": {
      "functionId": "bigben",
      "region": "us-central1"  // optional (see note below)
      "pinTag": true           // optional (see note below)
    }
  } ]
}
like image 82
Idan Gozlan Avatar answered Mar 20 '26 10:03

Idan Gozlan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!