Discover the best way to set up Firebase Hosting for all types of websites. Check out this easy-to-follow guide to handle multiple projects on one Firebase account seamlessly.
Setting up Firebase Hosting for multiple sites makes it super easy to manage and roll out content smoothly across different domains or subdomains all from one Firebase project. Perfect for businesses juggling separate websites or different site versions, like staging and production. The steps? Start by initializing Firebase in your project, then update the firebase.json
file to detail multiple hosting setups. Finally, deploy your sites using Firebase CLI commands. Leveraging this feature guarantees consistent and efficient site management straight through Firebase Hosting.
First things first, let's get the Firebase CLI tool installed. If you haven't done this yet, you can easily do it with npm:
npm install -g firebase-tools
Now, head over to your project directory in the terminal and run:
firebase init
When prompted, select "Hosting" and follow the steps. This will create a firebase.json
configuration file in your project directory.
Open up the firebase.json
file. To support multiple sites, you'll need to use the hosting
array configuration. Here's an example setup:
{
"hosting": [
{
"target": "site1",
"public": "site1-public",
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
],
"rewrites": [ ... ],
"redirects": [ ... ],
"headers": [ ... ]
},
{
"target": "site2",
"public": "site2-public",
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
],
"rewrites": [ ... ],
"redirects": [ ... ],
"headers": [ ... ]
}
]
}
In this example, site1
and site2
are the IDs for the different sites. The public
field specifies the directory from which files will be served.
Next, find your Firebase project IDs for the different sites and set them using the Firebase CLI:
firebase target:apply hosting site1 <projectID-1>
firebase target:apply hosting site2 <projectID-2>
Replace <projectID-1>
and <projectID-2>
with your actual Firebase project IDs.
To deploy the sites, use these CLI commands:
firebase deploy --only hosting:site1
firebase deploy --only hosting:site2
Or, if you want to deploy both sites at once, just run:
firebase deploy
If you need to, you can customize the rewrites
, redirects
, and headers
sections within each hosting configuration in firebase.json
. Each site can have its own specific rules:
"rewrites": [
{
"source": "**",
"destination": "/index.html"
}
],
"redirects": [
{
"source": "/old-path",
"destination": "/new-path",
"type": 301
}
],
"headers": [
{
"source": "/path/to/file",
"headers": [
{
"key": "Cache-Control",
"value": "max-age=3600"
}
]
}
]
Tweak these as needed based on what each site requires.
This setup lets you host multiple sites using a single Firebase project, taking advantage of the flexibility of the firebase.json
configuration.
Explore our Firebase tutorials directory - an essential resource for learning how to create, deploy and manage robust server-side applications with ease and efficiency.
Nocode tools allow us to develop and deploy your new application 40-60% faster than regular app development methods.
Save time, money, and energy with an optimized hiring process. Access a pool of experts who are sourced, vetted, and matched to meet your precise requirements.
With the Bootstrapped platform, managing projects and developers has never been easier.
Bootstrapped offers a comprehensive suite of capabilities tailored for startups. Our expertise spans web and mobile app development, utilizing the latest technologies to ensure high performance and scalability. The team excels in creating intuitive user interfaces and seamless user experiences. We employ agile methodologies for flexible and efficient project management, ensuring timely delivery and adaptability to changing requirements. Additionally, Bootstrapped provides continuous support and maintenance, helping startups grow and evolve their digital products. Our services are designed to be affordable and high-quality, making them an ideal partner for new ventures.
Fast Development: Bootstrapped specializes in helping startup founders build web and mobile apps quickly, ensuring a fast go-to-market strategy.
Tailored Solutions: The company offers customized app development, adapting to specific business needs and goals, which ensures your app stands out in the competitive market.
Expert Team: With a team of experienced developers and designers, Bootstrapped ensures high-quality, reliable, and scalable app solutions.
Affordable Pricing: Ideal for startups, Bootstrapped offers cost-effective development services without compromising on quality.
Supportive Partnership: Beyond development, Bootstrapped provides ongoing support and consultation, fostering long-term success for your startup.
Agile Methodology: Utilizing agile development practices, Bootstrapped ensures flexibility, iterative progress, and swift adaptation to changes, enhancing project success.