Search code examples
javascriptnode.jsfirebasegoogle-cloud-functionsfirebase-hosting

Can't reference public folder from node.js deployment with firebase


After watching Node.js apps on Firebase Hosting I tried to create a project with Polymer and NodeJs/express and firebase hosting.
In the linked Video it is shown that firebase would serve by default the static public/index.html file which is why they remove it to then serve a dynamic one. However, this particular file is in the same functions directory and not anymore placed in the public folder.

Does this mean that my whole project should be placed in the functions folder or just the app entry-point? I am not able to send a file that is placed in my public folder as shown below.

  • project
    • functions
      • server.js
    • public
      • index.html


app.get('*', (req, res) => {
   res.sendFile(path.join(__dirname, '/public/index.html'));
})

I believe firebase is hosting the public and the function folder differently or am I referencing just wrong?


Solution

  • You'll need to nest your public folder inside the functions folder to be able to reference files from it in your functions. You can do this just by changing the public setting in firebase.json to be e.g. functions/public and then moving the directory inside functions.

    You would then be able to do something like you're describing.