Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

202
Views
Firebase cloud functions CAN'T find static files in public folder
  • project
    • stripejs
      • functions
        • index.js

        • public

          • success.html

It's been hours I'm trying to redirect an API ( using cloud functions) to my html page (inside the public folder).

router.get('/finishOnboarding',  async (req,res) => {

    let content =  path.resolve('../public/success.html')
    res.sendFile(content);

});

I tried multiples things.

  1. put the public folder Outside of the functions folder, then i noticed i need to nest it inside because when deploying it need to be accessed in google cloud

  2. using __dirname + absolute path

No matters what I do, When I'm checking the Functions logs I always got the same error :

Error: ENOENT: no such file or directory, stat '/public/success.html'

If I'm trying to redirect using

path.join(__dirname, '/public/success.html');

I got :

Error: ENOENT: no such file or directory, stat '/workspace/routes/public/success.html'

firebase.json is configured as needed

{
  "hosting": {
    "public": "functions/public",
    "ignore": [
      "firebase.json",
      "**/.*",
      "**/node_modules/**"
    ],
    "rewrites": [
      {
        "source": "**",
        "function": "app"
      }
    ]  
  },
  "emulators": {
    "hosting": {
      "port": 5003
    }
  }
}

Where is the problem coming from? I'm sure its a simple problem with the paths, but Im very confused..

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Cloud Functions and Hosting run on completely separate infrastructure, so you can't reach from one to the other with a path type call.

If you want to redirect the user, you'll need to send a redirect instruction on the response. Doing that means the browser will get the instruction to request a different URL, and that request will then be served by Firebase Hosting.

If you want to rewrite the response (so serve HTML from a different location within your code), you will need to have those files inside (or under) the functions folder:

  • project
    • stripejs
      • functions
        • index.js

        • public

          • success.html
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!