Linked Questions

Popular Questions

Cannot have nested routes in firebase cloud function

Asked by At

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

  "functions": {},
  "hosting": {
    "public": "public",
    "rewrites": [
        "source": "/users",
        "function": "usersMicroservice"
    "ignore": [

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




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.

Related Questions