74

I need to pull down my code from a firebase hosted site, I created a site this past summer and no longer have the code locally on my laptop. I would like to recode some of the pieces, but don't have the source code anymore (other than the javascript and css I can glean from the served pages). I can't find a way to get the code from the firebase site, does anyone have any ideas?

Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441
Randal Wilcox
  • 759
  • 1
  • 5
  • 6
  • 7
    it does seem strange to have to post questions on here, but that is what firebase asks users to do: "For API questions and general technical help, we encourage you to use the Firebase tag on StackOverflow. We monitor the questions very closely, and using StackOverflow allows others to benefit from the answers" – Randal Wilcox Oct 09 '14 at 20:01
  • 1
    Randal, it's not at all strange to post API or technical questions here. @Mooseman this isn't a documented or supported feature of Firebase and therefore isn't a documentation issue. – Kato Oct 09 '14 at 20:28
  • Firebase hosting just keeps the static resources of your web site, so it (normally) doesn't contain anything but JavaScript, CSS and HTML. What other code than JavaScript are you looking for? – Frank van Puffelen Oct 09 '14 at 21:16
  • 3
    The angular views that I wrote for the project – Randal Wilcox Oct 09 '14 at 23:16

4 Answers4

90

You should of course add your own version control (e.g. git) to manage your revisions and backups so this doesn't occur.

There is a script you can run to download all the assets using the CLI. You can find the script and instructions here. It can also be run using npx:

npx https://gist.github.com/mbleigh/9c8680cf319ace2f506f57380da66e7d <site_name>

Note that this only returns the compiled/rendered content from the specified public folder and not any precompiled source you may have had on the development machine.

Since your files are static assets, you could also scrape them using wget. This is inferior for advanced apps as you'll get the rendered content and not the source:

wget -r -np https://<YOURAPPNAME>.firebaseapp.com

Read more on scraping web sites here: https://apple.stackexchange.com/questions/100570/getting-files-all-at-once-from-a-web-page-using-curl

Kato
  • 40,352
  • 6
  • 119
  • 149
  • Interestingly, "firebase deploy" doesn't seem to deploy my entire project (modulo the "ignore" setting in firebase.json), only the resources needed by my index.html file. – Andrew Swan Mar 31 '15 at 22:15
  • 2
    Firebase deploy does upload all the files, wget just might only scrape the ones it can access through your index.html – Chris Raynor Apr 01 '15 at 15:31
  • 1
    what is windows version of unix's wget `-r -np`? there is no -r for wget on windows 10 – roberto tomás Feb 13 '17 at 21:46
  • 1
    @robertotomás in W10 you can use unix packages through scoop. First navigate to [scoop](https://scoop.sh) and install it. Then you'll get a `scoop` available in terminal (cmd), type `scoop install wget` and you'll be installing a linux package. Finally if you are a dev and use W10 for work, I'd recommend you to enable dev tools. – simultsop Dec 23 '18 at 00:10
  • I tried this method `wget -r -np https://.firebaseapp.com` its working but not all files are downloading in macbook. Some folders are missing. Why? @Kato – Jamshaid Alam Sep 18 '20 at 08:11
  • Firebase hosting _only_ has the files from your public folder. If you use webpack or any other build scripts, you've probably only uploaded your compiled files to hosting. You can't download something that was never uploaded. – Kiana Mar 09 '21 at 20:45
  • When using gist script from `mbleigh ` you should omit `https://` and `.firebaseapp.com`. It works seamlessly with just the app name. – Siddharth Kaushik Jul 31 '22 at 12:36
8

Maybe this answer is not exactly consisted with requested direction but in order to list the files which are being uploaded you could during the deploy use --debug switch:

firebase deploy --debug

With this option you will see the POST request. Something like that:

>>> HTTP REQUEST POST https://deploy.firebase.com/firebase/yourapp/releases?token=XXX public=dist, version=-KE5UDaj7oCppckjEBaE, prefix=-KE5UDaj7oCppckjEBaE/, manifest=[path=404.html, object=404.html, path=scripts\main\main.html, object=scripts\main\main.html, path=scripts\scripts.d6106dbd.js, object=scripts\scripts.d6106dbd.js, path=scripts\vendor.68cdc83b.js, object=scripts\vendor.68cdc83b.js, path=styles\main.5b335e2d.css, object=styles\main.5b335e2d.css, path=styles\vendor.d41d8cd9.css, object=styles\vendor.d41d8cd9.css], rules=undefined <<< HTTP RESPONSE 200 server=nginx, date=Wed, 30 Mar 2016 07:46:31 GMT, content-type=application/json; charset=utf-8, content-length=34, connection=close, access-control-allow-origin=*, access-control-allow-methods=GET, PUT, POST, DELETE, OPTIONS, strict-transport-security=max-age=31556926; includeSubDomains; preload, x-content-type-options=nosniff

It might helps to trace what is rally uploaded to firebase hosting.

But I agree that the lack option to simple list the files on firebase hosting do not encourage to use this service.

Przemek Nowak
  • 7,173
  • 3
  • 53
  • 57
  • 4
    I don't get any `object` or `path` in `HTTP REQUEST POST` if I run `firebase deploy --debug`. It seems like it doesn't work anymore – Matt May 25 '18 at 09:53
  • It's better & easier to use the hosting API to get your current version, and then list the files in that version. The gist [1] is an example of how to do that [1](https://gist.github.com/mbleigh/9c8680cf319ace2f506f57380da66e7d) – Kiana Mar 09 '21 at 20:44
0

I've tried https://stackoverflow.com/a/26287429/145122, but it doesn't download all the files. The following command worked for my website.

wget -mpEk https://yoursite.com
Ives.me
  • 2,359
  • 18
  • 24
-9
  1. Its quite simple,the only thing you need to do is go to your hosted site.
  2. right click and go to inspect element => debugger.There you will find a static folder.
  3. relax,all your js files are there(front end only),you can copy your code.
slfan
  • 8,950
  • 115
  • 65
  • 78