0

I am trying to implement a firebase hosting rewrite. Here is my firebase.json

{
  "functions": {},
  "hosting": {
    "public": "public",
    "rewrites": [
      {
        "source": "/users",
        "function": "usersMicroservice"
      }
    ],
    "ignore": [
      "firebase.json",
      "**/.*",
      "**/node_modules/**"
    ]
  }
}

My functions/index.js file looks like this

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

const app = express();

app.get("/users", (req, res) => res.json({message: "hello world"}));
app.get("/users/next", (req, res) => res.json({message: "hello world 2"})));


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

I am running my server locally. There are two urls that appear in the logs. They are

http://localhost:5001/test-development/us-central1/usersMicroservice

and

http://localhost:5000

The first url is the direct path to my cloud function and the latter is my "hosting" url. When I make a requests to the cloud function everything works as expected. However, when I make a GET request to http://localhost:5000/users/1 I get a 404 Page Not Found message, but when I make a GET request to http://localhost:5000/users I get the expected json response.

I am new to firebase hosting and cloud functions. Not sure what I might be doing incorrectly. Any help is greatly appreciated.

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
  • This post https://stackoverflow.com/questions/44959652/firebase-hosting-with-dynamic-cloud-functions-rewrites solved my issue for me. – EuklidianSpace Feb 05 '19 at 00:33

1 Answers1

0

Try this:

app.get("/users/:next", (req, res) => res.json({message: "hello world 2 " + req.params.next })));

chris
  • 184
  • 5