Sebastian Altamirano
Sebastian Altamirano

Reputation: 37

Express app using firebase functions

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!

Upvotes: 0

Views: 1396

Answers (1)

Doug Stevenson
Doug Stevenson

Reputation: 317968

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.

Upvotes: 2

Related Questions