问题
I'd like to use Google's Webmaster Tools to add domain verification for my "site", which is entirely made up of Cloud Functions for Firebase:
https://us-central1-<project-id>.cloudfunctions.net/
However I cannot figure out how to do this in a way that would work successfully.
The recommended way is to download and serve an HTML file with a verification key. However, I cannot seem to create a function with a dot.
exports['googleKEY.html'] = functions...
This fails when trying to deploy.
An alternative is to put a meta tag in my "homepage", but that also does not work as I cannot seem to create an index page.
exports[''] = functions...
and
exports['index.html'] = functions...
Also fail.
Is there a way to do this domain verification just through functions? I'd appreciate guidance.
回答1:
So... I think I finally may have a solution.
There is no direct way to verify a Firebase Functions domain (https://*.cloudfunctions.net
) BUT verifying Firebase Hosting domain (https://*.firebaseapp.com
) is easy (using verification file). So let's start with that.
There is a config option in Hosting to setup url rewrite to serve a Function. (Documented here)
This is a modified example config from the link above, opening url https://<your-project-id>.firebaseapp.com/covertFnBigben
to invoke Function bigben
.
{
"hosting": {
"public": "public",
// Add the following rewrites section *within* "hosting"
"rewrites": [
{
"source": "/covertFnBigben", "function": "bigben"
}
]
}
}
So after successfull verification of your Firebase Hosting domain you can use that domain to call Firebase Functions.
回答2:
I had the same problem: I wanted to validate my Domain Ownership in the Google Search Console. But the domain is actually a Firebase Cloud Functions domain (https://*.cloudfunctions.net
). I found a super easy solution today:
1) When adding a property in Google Search Console, select the method "URL prefix" and enter the url of the function you will create in step 3 (i.e. https://foobar.cloudfunctions.net/googleDomainVerification
).
2) Select the method "HTML tag" and copy the meta-tag.
3) Create a https function that you push on Firebase Cloud Function. Don't forget to copy your meta-tag from step 2:
exports.googleDomainVerification = functions.https.onRequest((req, res) => {
res.status(200).send('<!DOCTYPE html> <html> <head> YOUR_META_TAG_HERE </head> <body> </body> </html>')
})
4) Wait a minute then press "Verify" on the Google Search Console
That's it. Everything should work now :)
来源:https://stackoverflow.com/questions/49661425/how-to-perform-domain-verification-for-firebase-functions