Waggoner_Keith
Waggoner_Keith

Reputation: 600

Firebase Hosting can't find Express Endpoints

I have set up hosting on Firebase and configured my Node.js express app following the documentation provided by Google. Including the proper folder structure and command line instructions to init firebase and firebase-functions.

Folder Structure:

Project
-- functions
   -- node_modules
   -- index.js
   -- package.json
-- public
   -- index.html
   -- 404.html
.firebaserc
firebase.json

I have added the express app to the firebase functions http request via the code below:

// Set up endpoint
app.get('/api', (req, res) => {
    res.json({
        message: 'Welcome to the Line Prophet API.  Good luck.'
    })
});

/**
 * Firebase cloud functions 
 */
exports.app = functions.https.onRequest(app);

My Firebase.json file is set up to direct all request to the app destination:

{
  "hosting": {
    "public": "public",
    "rewrites": [
      {
        "source": "**",
        "destination": "app"
      }
    ]
  }
}

Once I run firebase deploy from my parent directory everything goes through fine and it says the app is deployed: enter image description here

However after that I navigate to https://line-prophet.web.app/api and I recieve a 404 page not found error.
enter image description here

I have tried to run this locally with firebase serve and I have the same issue. This was working briefly which is why I feel as though everything is set up correctly, however after deploying again it has broken for good. Any tips are appreciated. Thanks!

The latest deployments say there are only 4 files deployed to Firebase which seems very low. I checked the Functions tab and I do see that "app" is in there and the source code is correct.

Upvotes: 0

Views: 1209

Answers (1)

Waggoner_Keith
Waggoner_Keith

Reputation: 600

Thanks to @LawrenceCherone changing the firebase.json file to:

"rewrites": [
      {
        "source": "**",
        "function": "app"
      }
    ]

solved my issue. I was using destination instead of function because of the online docs, but it makes more sense to direct all requests to the function you have set up to handle http request.

Upvotes: 2

Related Questions