Vamsidhar Muggulla Vamsidhar Muggulla - 1 month ago 11
Node.js Question

How to access firebase hosting file from firebase function

I have a simple firebase function it has to send a file in response to the request the file is in /app/one.html

my project directory structure

blog
|____app
|____index.html
|____one.html
|____functions
|____index.js


I have to access one.html and send it from senFile()

index.js

const functions = require('firebase-functions');
exports.blog = functions.https.onRequest((req, res) => {
res.status(200).sendFile('app/one.html'); #here I need something to do
});

Answer Source

As far as I know firebase deploy for functions deploys only the contents of functions folder. So if you move/copy your app folder to inside of functions folder you can achieve what you are trying to do.

blog
|____functions
      |____app
          |____index.html
          |____one.html
      |____index.js

After you changed the paths correctly you can send the file like an express app.

res.sendFile(path.join(__dirname + 'app/one.html'));