0
votes

Im trying to run an Express app into firebase, i'm following the steps of this official video:

Node.js apps on Firebase hosting crash course

My Express app is actually running on this URL

http://localhost:5001/my-app/us-central1/app/test

But on the video, the demostration is running on this url

http://localhost:5000/test

So, i'm really confused about this, i'been made everything as the tutorial shows

this is my code on functions/index.js

const functions = require('firebase-functions');

const express = require('express')
const app = express()

app.get('/test', (req, res) => {
    res.send(`Well if i'm reading this the app is working`)
})


exports.app = functions.https.onRequest(app)

And this is firebase.json

{
  "hosting": {
    "public": "public",
    "rewrite":[{
      "source": "/test",
      "function": "app"
    }],
    "ignore": [
      "firebase.json",
      "**/.*",
      "**/node_modules/**"
    ]
  }
}

What i'm doing wrong? if i enter to localhost:5000 i just get the public static index.html, i just want to control the app by myself.

I hope you can give me a little help to get documented, thanks!

1
The firebase.json maps /test to your app, so localhost:5000/test should serve the express app.Frank van Puffelen
That's the logical behavior but isn't working on that way, instead is rendering the public/index.html fileSebastian Altamirano
How are you running the functions locally?Frank van Puffelen
This is printed by the console: </br>functions: Preparing to emulate functions. Warning: You're using Node.js v8.11.2 but Google Cloud Functions onl 6.11.1. i hosting: Serving hosting files from: public + hosting: Local server: localhost:5000 + functions: app: localhost:5001/r-commerce/us-central1/appSebastian Altamirano
So it looks like your app locally is being server from localhost:5001/r-commerce/us-central1/app. What happens if you open that URL.Frank van Puffelen

1 Answers

2
votes

The issue here is that Firebase Hosting will serve static content that matches any paths before using any rewrites. If you want to control a path with Cloud Functions, you will have to make sure that there is no static content that matches the path.

For single page apps in particular, it's critical to remove index.html, as that will always be served as static content.