Proxying external API for Firebase Hosting?
Asked Answered
C

1

12

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)!

Coprophagous answered 22/10, 2018 at 11:1 Comment(0)
V
1

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)
    }
  } ]
}
Vitals answered 10/8, 2023 at 21:58 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.