exoslav exoslav - 6 months ago 256
Javascript Question

run Firebase locally

I am new with Firebase and I am struggling with its docs for an 2 hours now, and I canĀ“t figure out how to run my local project with Firebase (Firebase for web).

My app is like:

-- node_modules
-- app
-- index.html
-- src
-- css, js, etc.


Basically I want to run my app from app/index.html. I have installed
firebase tools
, run
firebase init
(i am not familiar with all init options) and then run
firebase serve
.

It throws error "an unexpected error has occurred", probably due to missing public directory (but I don't want any "public" dir in my app).

I have also put firebase app code from my Firebase project to my index.html, but it logs error:
Error: Illegal url for new iframe
and
This domain is not authorized for OAuth operations for your Firebase project. Edit the list of authorized domains from the Firebase console.

Answer

When you init, it creates a file:

firebase.json

that looks like this:

{
  "firebase": "yourProjectName",
  "public": "./someFolder",
  "ignore": []
}

The folder that is being served is the one specified by the public property. So if you want to serve the app folder of your project you just have to replace the string:

  "public": "./app",

This error happens because you didn't authorize operations.

This domain is not authorized for OAuth operations for your Firebase project. Edit the list of authorized domains from the Firebase console

You have to login via the console using the command:

firebase login

Then, it will open the browser and ask for authorization if I remember correctly.