问题
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