Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

203
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda