1

I am trying to follow this walkthrough: https://www.youtube.com/watch?v=LOeioOKUKI8 for setting node app hosting on Firebase.

I cannot get the local version to work (everything works fine deployed)

I have set up went the project using the CLI and everything fine. In the walkthrough, he never loads the finished project locally. Does that mean you can't work with things locally to a certain point?

Here is the code I am running in my index.js and the rewrites setup in the firebase.json

firebase.json

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

index.js (inside the functions/ directory)

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

const firebaseAdmin = admin.initializeApp(
    functions.config().firebase
);

const app = express();

// Products
app.get('/products', (request, response) => {
    response.json({
        "products": [{
            "type": "Type 1",
            "title": "Product 1"
        }]
    });
});

// Main export of app
exports.app = functions.https.onRequest(app);

When I run the local server using firebase serve

I get this in the terminal:

✔  functions: Using node@8 from host.
✔  functions: Emulator started at http://localhost:5001
i  functions: Watching "/Users/justbane/_FireBase/relatables_app/functions" for Cloud Functions...
i  hosting: Serving hosting files from: public
✔  hosting: Local server: http://localhost:5000
⚠  Default "firebase-admin" instance created!
i  functions: HTTP trigger initialized at http://localhost:5001/relatables-d98b3/us-central1/app

But when I access the localhost address http://localhost:5000/products

I get Cannot GET /relatables-d98b3/us-central1/app/products in the browser

justbane
  • 43
  • 3
  • 1
    having very similar issues, and downgrading firebase-tools solved it for me. `npm uninstall -g firebase-tools && npm i -g firebase-tools@6.8.0`. May need to `npm rebuild` in both the main folder and functions folder afterwards – mark May 13 '19 at 01:06
  • Thanks, @mark - Tried that and still no dice. I tried removing the express layer and just exporting the function directly and that did work locally and deployed. I guess you can't use express and develop locally? – justbane May 13 '19 at 15:56
  • one other thing to check is that you don't have any static web content in the public folder that matches the client requested URL, otherwise that will be served instead of the cloud function https://stackoverflow.com/a/44873297/598093 – mark May 13 '19 at 22:51

0 Answers0