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