My intention is to redirect https://example.com/admin to my firebase function named admin. So I have the following code in the firebase.json:
{
"hosting": {
"public": "build",
"ignore": ["firebase.json", "**/.*", "**/node_modules/**"],
"rewrites": [
{
"source": "/admin{,/**}",
"function": "admin"
},
{
"source": "**",
"destination": "/index.html"
}
]
}
}
I've followed the instructions from this website: https://firebase.google.com/docs/hosting/functions
Using my browser, if I go to https://my-server-my-project.cloudfunctions.net/admin everything works an looks fine. But if I go to https://example.com/admin, this is what I get instead:
Related
I'm using firebase hosting. I have index.html file.
It's opening via Both Firebase URL and Custom Domain.
If anyone tries open example.com it should open index.html
But if anyone try to open example.com/?link=https://google.com it should dynamically open the URL in link parameter.
I don't know what I'm doing wrong. Even if the link parameter is present. It still opens the index.html file.
Here is my firebase.json
{
"hosting": {
"public": "public",
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
],
"appAssociation": "AUTO",
"rewrites": [
{
"source": "/?link**",
"dynamicLinks": true
},
{
"source": "!/?link**",
"destination": "/index.html"
}
]
}
}
You should remove the rewrite rule for index.html
{
"source": "!/?link**",
"destination": "/index.html"
}
and remove ? on the dynamicLinks rewrite rule source. It should look like this.
{
"hosting": {
"public": "public",
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
],
"appAssociation": "AUTO",
"rewrites": [{
"source": "/link**",
"dynamicLinks": true
}]
}
}
Deploy the changes again and this should set https://example.com/link as your Dynamic Link domain. You can test if the FDL domain functional by manually adding FDL parameters on the domain.
i.e. https://example.com/link?link=https://google.com
I wan´t to make routing with firebase hosting
"rewrites": [
{
"source": "/api/**",
"function": "api"
},
{
"source": "/**",
"function": "myfunction"
},
{
"source": "**",
"destination": "/index.html"
}
]
/api/test should route to api function
/anything should route to myfunction
/ should route to index.html on firebase hosting
for some reason/api/test is being routed to myfunction. I can´t get the rewrite order right. can you help me? thanks
update: this is what I have now
{
"hosting": {
"public": "build",
"ignore": ["firebase.json", "**/.*", "**/node_modules/**"],
"cleanUrls": true,
"trailingSlash": false,
"rewrites": [
{
"source": "/api/**",
"function": "api"
},
{
"source": "/**",
"function": "myfunction"
}
]
},
"functions": {
"predeploy": ["npm --prefix \"$RESOURCE_DIR\" run lint"]
}
}
and myFunction is the one that´s still being executed and ignoring what I set
/api/test is executing myfunction instead of api
/something/test is executing myFunction as expected
"/" (or no slash at all after your domain name) automatically routes to "index.html". So simply remove the "source": "**" item. Specifically remove:
,
{
"source": "**",
"destination": "/index.html"
}
I also like to add the following to my Firebase Hosting config (firebase.json):
"cleanUrls": true,
"trailingSlash": false,
I am building a Nuxt app hosting on firebase function. When I see the URLs on local, they look fine, however, on firebase they end with "/" before queries. Am I missing any settings?
example:
https://xxxxx.firebaseapp.com/select-prefecture/?type=blocks
http://localhost:4000/select-prefecture?type=blocks
production
local
firebase.json
{
"hosting": {
"site": "xxxxxx",
"public": "public",
"rewrites": [
{
"source": "**",
"function": "app"
}
],
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
]
}
}
Does anyone know a good way to put a static Firebase site into maintenance mode while performing some database upgrade?
I've tried to configure the rewrite with custom headers but it's not working. Firebase hosting appears to return both the default status (200) and the custom status (503) in the response.
My firebase.json:
{
"hosting": {
"public": "public",
"ignore": ["firebase.json", "**/.*", "**/node_modules/**"],
"rewrites": [
{
"source": "**",
"destination": "/index.html"
}
],
"headers": [
{
"source": "**",
"headers": [
{
"key": "status",
"value": "503"
}
]
}
]
}
}
Response headers from chrome:
This is my firebase.json file:
{
"hosting": {
"target": "md-viewer",
"public": "public",
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
],
"rewrites": [
{
"source": "/",
"destination": "create_md.html"
},
{
"source": "/view/*",
"destination": "show_md.html"
}]
}
}
When running firebase serve, the rewrites work as expected. However, deploying and opening my app ("appname.firebaseapp.com") returns 404. The deployment is succesful since I can customize the 404 page, and access my files by asking for them directly (appname.firebaseapp.com/show_md.html, for example).
What's wrong? Shouldn't firebase serve mirror online behaviour?
If the "destination" key on the rewrite rule is a file, it has to be referenced with an absolute path:
"rewrites": [
{
"source": "/",
"destination": "/create_md.html"
},
{
"source": "/view/**",
"destination": "/show_md.html"
}]
Also, the "/view" rewrite needs two asterisks, according to the documentation.