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

117
Visualizações
JS not found - express app - cloud functions

I am using Google cloud functions with express js to serve up some HTML files. My js files do not show up in the browser. It says 404 not found.

My folder structure

Folder structure

My HTML file:

    <html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <script type="module" src="/public/js/auth.js"></script>
  </head>
  <body>
    <div class="content__container">
      <h1>Hello world</h1>
    </div>
    <script src="/public/js/main.js"></script>
  </body>
</html>

My app.js

const functions = require("firebase-functions");
const express = require("express");
const path = require("path");


const app = express();

app.use("/js", express.static(path.join(__dirname, "public/js")));

exports.admin = functions.https.onRequest((req, res) => {
  res.sendFile(path.join(__dirname, "public", "admin.html"));
});

The error in the browser when I invoke the cloud function admin

Js not showing in browser

Functions directory

Functions directory

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

I think you forgot to declare app in your js file

const app = express();

In your HTML file:

<script src="./js/main.js">

If js is your static/public dir:

<script src="./main.js">

Also, in your js file:

res.sendFile(path.join(__dirname, "admin.html"));
about 4 years ago · Juan Pablo Isaza Relatório

0

From where have you exposed the Express app? There must be a HTTP function that should look something like this:

const app = express()
app.use("/js", express.static(path.join(__dirname, "public/js")));

exports.api = functions.https.onRequest(app);
// This is missing? or you are not requesting at this URL

When you add the above function, your JS file should be available at the following URL:

'http://localhost:5001/photography-5b191/us-central-1/api/js/main.js'
// notice the function name ('api' in this case) ---->^^^

The function name that has exposed the Express app is missing from the URL in the network log that you've shared.

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