fodma1
fodma1

Reputation: 3535

Dynamic firebase.json file

It is quite difficult to keep track of the CSP rules in the firebase.json file, therefore I decided to add a script that constructs the proper rules. Now I need to manually update the firebase.json file every time I am changing something in the CSP configuration. Is there any way to dynamically configure firebase? I was hoping to achieve it with a simple renaming as it worked for many services grunt.json -> grunt.js I guess I can use some sort of templating but I wonder if there's a built-in mode to dynamically construct headers, rules etc for firebase.

Upvotes: 1

Views: 869

Answers (1)

Michael Bleigh
Michael Bleigh

Reputation: 26343

There isn't a built-in way to generate firebase.json on command. I would recommend creating a script, e.g. npm run deploy that first generates your firebase.json content and then runs firebase deploy. That way you can make sure it's always regenerated before deployment.

// configureFirebase.js
const fs = require('fs');

const config = {
  hosting: {
    // ...
  }
}

fs.writeFileSync(__dirname + '/firebase.json', JSON.stringify(config));
// package.json
{
  "scripts": {
    "deploy": "node configureFirebase.js && firebase deploy"
  }
}

Upvotes: 4

Related Questions