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/**"
]
}
}
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 have two firebase projects: myapp for prod, and myapp-dev for dev environment.
I first used the firebase cli to init my project with "myapp" and so all the files were generated with this, including the hosting resource myapp (so I can deploy my app to myapp.web.app).
Then I have added a second firebase project ("myapp-dev"). I run those
firebase use --add myapp-dev # I have selected the right myapp-dev firebase project and set `dev` as short name
firebase target:apply hosting myapp-dev myapp # note here that I also use name "myapp" as resource
I have manually changed my .firebasesrc because I want the dev project to be default...
So my .firebasesrc looks like this
{
"projects": {
"default": "myapp-dev",
"prod": "myapp"
},
"targets": {
"myapp": {
"hosting": {
"myapp": [
"myapp"
]
}
},
"myapp-dev": {
"hosting": {
"myapp": [
"myapp"
]
}
}
}
}
and firebase.json
{
"hosting": [
{
"target": "myapp",
"public": "public",
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
],
"rewrites": [
{
"source": "**",
"destination": "/index.html"
}
]
}
],
"functions": {
"predeploy": [
"npm --prefix \"$RESOURCE_DIR\" run lint"
]
}
}
Now when I ran those lines, the webapp got deployed to the prod env, the functions to the dev env...
firebase use myapp-dev
firebase deploy
EDIT
Running firebase target:apply hosting myapp myapp-dev helped !
In my case I had the same app deploying to 2 different environments (development and production). The documentation is not very clear on this scenario, took some playing around to get the right config.
.firebaserc
{
"projects": {
"production": "myapp-prod",
"development": "myapp-dev"
},
"targets": {
"myapp-prod": {
"hosting": {
"myapp": [
"site-name-prod"
]
}
},
"myapp-dev": {
"hosting": {
"myapp": [
"site-name-dev"
]
}
}
}
}
firebase.json
{
"hosting": [{
"target": "myapp",
"public": "dist",
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
],
"rewrites": [ {
"source": "**",
"destination": "/index.html"
} ]
}]
}
To deploy to production run
firebase use production
firebase deploy
To deploy to development
firebase use development
firebase deploy
When you run firebase deploy in the project, it uses the target specified in the hosting section on the firebase.json to deploy to the site name specified in the hosting section of the target in the .firebaserc
I think your config should be something like this.
file .firebasesrc
"targets": {
"myapp-dev": {
"hosting": {
"myapp-dev": [
"myapp-dev"
],
"myapp": [
"myapp"
]
}
}
}
file firebase.json:
"hosting": [
{
"target": "myapp-dev",
"public": "build",
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
],
"rewrites": [
{
"source": "**",
"destination": "/index.html"
}
]
},
{
"target": "myapp",
"public": "dist/myapp", /* folder */
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
],
"rewrites": [
{
"source": "**",
"destination": "/index.html"
}
]
}
]
and then deploy using target documentation
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:
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.
I have a URL structure to a "project detail" page that looks like this: john/project/eRdKn6 (where "john" is the username and "eRdKn6" is the project id). I want this to be rewritten to the file project.html, where I parse the document.location and load the appropriate data. So the username and the project id should be dynamic.
The rule in firebase.json that I have looks like this:
{
"source": "*/project/*",
"destination": "/project.html"
}
However, Firebase 404's when I try to load http://example.com/john/project/eRdKn6.
I've tried to make only the last part dynamic, as a test (e.g. {"source": "john/project/*", "destination": "/project.html"} but I also get a 404.
The project.html is in the public folder.
Here is my full firebase.json file:
{
"firebase": "example",
"public": "public",
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
],
"rewrites": [
{"source": "*/project/*", "destination": "/project.html"}
]
}
It seems the issue is that source requires a starting slash, e.g. /*/project/*. My full firebase.json now looks like this:
{
"firebase": "example",
"public": "public",
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
],
"rewrites": [
{"source": "/*/project/*", "destination": "/project.html"}
]
}
This seems a documentation issue, since none of the examples cover this use case.