0
votes

Now I created a file by node server like

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

/* Express */
const app = express()
app.get("/test", (request, response) => {
  response.send("Hello from Express on Firebase!")
})

const api1 = functions.https.onRequest(app)


module.exports = {
  api1
}

firebase.json

    {
  "hosting": {
    "public": "public",
    "ignore": [
      "firebase.json",
      "**/.*",
      "**/node_modules/**"
    ]
  },
  "functions": {
    "predeploy": [
      "npm --prefix \"$RESOURCE_DIR\" run lint"
    ]
  }
}

and I have deployed it to firebase hosting and try tried access it on firebase hosting the index.html show up to me but when I require the /test it's return as 404.html page ! what's I'm missing ?

after updated firebase.json and added rewrites to

{
  "hosting": 
  {
    "public": "public",
    "rewrites": [
      {
          "source": "/test",
          "function": "app"
      }
    ]
  }
}

the message is different now enter image description here


The answer


I must to structured my project files to -project (folder) ---functions (folder)(contains on all nodejs files) ---public (filder)

1
Can you include your firebase.json file please? Did you forget to set the rewrite?JeremyW
@JeremyW thanks for your interesting ,I have added a firebase.json fileMahmoud Niypoo

1 Answers

1
votes

You need to include a rewrites section to your firebase.json file. That tells the Firebase servers how to route any requests that come in... and right now, you aren't telling it anything.

"hosting": {
    "rewrites": [
        {
            "source": "**",
            "function": "api1"
        }
    ]
}

This answer isn't actually an answer to your question, but it demonstrates the proper way to set up rewrites with cloud function express apps.