If you want to host your Gatsby output with Firebase Hosting, you can use the firebase.json
file to have redirects processed server side. This plugin adds redirects to that file for you
every time the Gatsby site is built.
- Add the Firebase hosting configuration to your project using
firebase init
- Add
"gatsby-plugin-firebase-redirects"
to the end of your plugins array ingatsby-config.json
. - Add the following environment variable to the environment where you want to build and deploy the project for Firebase:
IS_FIREBASE_BUILD=true
. Redirects will only be added tofirebase.json
if this variable is set to true. This is to avoid updating the file when runninggatsby build
locally and possibly committing hardcoded redirects to the repository.
The plugin doesn't accept any additional configuration currently.
It will add redirects to the firebase.json
file like this:
{
"hosting": {
...
"redirects": [
{
"source": "XXX",
"destination": "YYY",
"type": 123
}
...
]
}
}
This pattern receives the following replacements:
XXX
->fromPath
(including leading and trailing slashes, if any)YYY
->toPath
(including leading and trailing slashes, if any)123
-> Either 302 or 301 ifisPermanent
isfalse
ortrue
respectively
If you notice any bugs or errors, or if you need any help with setting up Firebase or redirects for your Gatsby project, get in touch with dlize.