Tengo este problema cuando intento obtener la carpeta /public con express en firebase.
Mi árbol de proyectos son:
ProjectRoot ├───functions -> index.js ├───node_modules ├───public -> index.html └───firebase.json Estoy tratando de obtener /public/index.html de /functions/index.js .
Este es mi index.js
const functions = require('firebase-functions'); const express = require("express"); var path = require('path'); const app = express(); // Static files app.use("/public", express.static(path.join(__dirname , '/..' , "/public"))); // Routes // Test1 is actually working app.get("/test1", (req, res) => { try{ res.send('🔥Module 1 is on fire🔥'); }catch(error){ console.error("Error Debug: "+ error); } }); // Test2 isn't working app.get("/test2", (req, res) => { try{ res.sendFile('/public/index.html'); }catch(error){ console.error("Error Debug: "+ error); } }); // Test3 isn't working app.get("/test3", (req, res) => { try{ res.sendFile(path.join(__dirname,'/..','/public/index.html')); }catch(error){ console.error("Error Debug: "+ error); } }); exports.app = functions.https.onRequest(app);La consola me tira cronológicamente
Function execution took 6 ms, finished with status code: 200 --> Test1 Works ENOENT: no such file or directory, stat '/public/index.html' Test2 code 404 ENOENT: no such file or directory, stat '/public/index.html' Test3 code 404Y finalmente mi firebase.json son
{ "hosting": { "public": "public", "ignore": [ "firebase.json", "**/.*", "**/node_modules/**" ], "rewrites": [ { "source": "**", "function": "app" } ] }, "functions": { "source": "/functions", "runtime": "nodejs16" } }