Firebase

How to configure Firebase Hosting with custom headers?

Find easy-to-follow instructions on setting up Firebase Hosting with custom headers. Boost your site's security and make your users happier today.

Developer profile skeleton
a developer thinking

Overview

Firebase Hosting is Google's platform for web hosting, tailored for developers seeking swift and secure solutions. Although it gives a robust set of default settings, developers might wanna tweak things for a bespoke user experience. One method is setting up custom headers. They can be used for various purposes: amping up SEO, boosting security, or activating specific web capabilities. Here’s a guide to help in configuring Firebase Hosting with these headers, covering the technical steps and the best practices.

Get a Free No-Code Consultation
Meet with Will, CEO at Bootstrapped to get a Free No-Code Consultation
Book a Call
Will Hawkins
CEO at Bootstrapped

How to configure Firebase Hosting with custom headers?

Step 1: Open the firebase.json File

Alright, so first things first, you need to locate the firebase.json file in your Firebase project directory on your computer. Once you find it, open it up with your favorite text editor. Notepad or Visual Studio Code works great for this.

Step 2: Define Hosting Configuration

Next, you want to find or create the "hosting" section in this JSON file. If you don't see a hosting section, no worries! You can add it yourself right after the { like this:

"hosting": {
}

Step 3: Add Headers to the Hosting Configuration

Now, let's get into the fun part—adding headers. Inside the hosting configuration, you'll need to define a "headers" section. It should look something like this:

"hosting": {
  "headers": [
  ]
}

Step 4: Add a Header Object

For each custom header you want to add, you'll need to create a new object in the "headers" array. Each header object should have two properties: "source" and "headers". The "source" property is a glob pattern that specifies which paths should have this header, and the "headers" property is an array of header objects. Each header object should have two properties: "key" and "value".

Here's an example of a header configuration that adds a Content-Security-Policy to every path ("source": "/**").

"hosting": {
  "headers": [
    {
      "source": "/**",
      "headers": [
        {
          "key": "Content-Security-Policy",
          "value": "default-src 'self' https://*.firebaseapp.com"
        }
      ]
    }
  ]
}

Step 5: Save and Deploy

Once you've added all the headers you need to your firebase.json file, go ahead and save it. Then, deploy your project using the Firebase CLI with the firebase deploy command. And just like that, your custom headers are now configured with Firebase Hosting.

Explore more Firebase tutorials

Complete Guide to Firebase: Tutorials, Tips, and Best Practices

Explore our Firebase tutorials directory - an essential resource for learning how to create, deploy and manage robust server-side applications with ease and efficiency.

Why are companies choosing Bootstrapped?

40-60%

Faster with no-code

Nocode tools allow us to develop and deploy your new application 40-60% faster than regular app development methods.

90 days

From idea to MVP

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.

1 283 apps

built by our developers

With the Bootstrapped platform, managing projects and developers has never been easier.

hero graphic

Our capabilities

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.

Engineered for you

1

Fast Development: Bootstrapped specializes in helping startup founders build web and mobile apps quickly, ensuring a fast go-to-market strategy.

2

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.

3

Expert Team: With a team of experienced developers and designers, Bootstrapped ensures high-quality, reliable, and scalable app solutions.

4

Affordable Pricing: Ideal for startups, Bootstrapped offers cost-effective development services without compromising on quality.

5

Supportive Partnership: Beyond development, Bootstrapped provides ongoing support and consultation, fostering long-term success for your startup.

6

Agile Methodology: Utilizing agile development practices, Bootstrapped ensures flexibility, iterative progress, and swift adaptation to changes, enhancing project success.

Yes, if you can dream it, we can build it.