What exactly is “source” in the context of Firebase rewrites?

落花浮王杯 提交于 2020-07-23 16:11:23

问题


I've read the Firebase documents and watched other tutorials multiple times and none of them explicitly explained what source was. so in Layman's terms, what exactly is source in the context of the code below?

"hosting": {
  // ...

  // Add the "rewrites" attribute within "hosting"
  "rewrites": [ {
    "source": "/bigben",
    "function": "bigben"
  } ]
}

回答1:


By declaring a rewrite, as follows

"rewrites": [ {
    "source": "/bigben",
    "function": "bigben"
  } ]

you actually "direct hosting requests to your function" as explained in the documentation.


If you look at the documentation about how to configuring the rewrites, you will see that for

  "rewrites": [ {
    "source": "/foo{,/**}",
    "destination": "/index.html"
  } ]

The rewrites attribute contains an array of rewrite rules, where each rule must include:

  • A source specifying a glob pattern

  • A destination, which is a local file that must exist

By doing

  "rewrites": [ {
    ...
    "function": "bigben"
  } ] 

instead of

  "rewrites": [ {
    ...
    "destination": "...."
  } ]

you redirect to the bigben function, as explained here.


So, "in Layman's terms", the platform redirects incoming requests coming from one or more sources to one or more destinations, and, in your case, the destination is a Cloud Function.




回答2:


See https://firebase.google.com/docs/hosting/functions .

Cloud Functions for Firebase lets you automatically run backend code in response to HTTPS requests. Your code is stored in Google's cloud and runs in a managed environment. There's no need to manage and scale your own servers.

For example use cases and samples for Cloud Functions integrated with Firebase Hosting, visit our serverless overview.



来源:https://stackoverflow.com/questions/56304145/what-exactly-is-source-in-the-context-of-firebase-rewrites

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!