Arrange FireStore Cloud Functions in multiple files - firebase

I have noticed a strange behaviour in FireStore Cloud Functions that if try to break my code up into separate files, I start to get this error:
info: Worker for app closed due to file changes.
I just created a simple express server and hosted it in a cloud function and was emulating it locally as described here.
https://www.youtube.com/watch?v=LOeioOKUKI8&t=244s
I even wrote tests for the same. Everything was working fine until I split the source code of my express app into individual routes (contained in separate .js files).

The only thing that message means is that the emulator noticed when a code file changed, and performed a hot reload of that code. Note that it's just an "info" level message, not an error and not even a warning.
If your project is not working the way you expect, then edit your question with the symptoms you're observing, along with the code.

Related

Changing firestore-debug.log location

I have a watcher in my Firebase project that automatically compiles and restarts the emulator whenever I change my code. It's nice except I think because of some race conditions I get a new firestore-debug.log or asidfhusudf.log file every time I save my code. How can I disable the log files or at least change the location where they are made?
firestore-debug.log is present in the same folder as firebase.json. You can see it in the directory you ran the command which will have a log of all the requests.
You are using typescript for functions so you can refer to the documentation on how function logs works for Typescript projects :
During firebase deploy, your project's index.ts is transpiled to index.js, meaning that the Cloud Functions log will output line numbers from the index.js file and not the code you wrote. To make it easier for you to find the corresponding paths and line numbers in index.ts, firebase deploy creates
functions/lib/index.js.map. You can use this source map in your preferred IDE or via a node module.
How debug output is stored in the firestore-debug.log is mentioned in the Documentation :
A basic debug function that prints Security Rules language objects, variables and statement results as they are being evaluated by the Security Rules engine.The outputs of debug are written to firestore-debug.log.
The debug function can only be called inside Rules conditions.debug function blocks are only executed by the Security Rules engine in the Firestore emulator, part of the Firebase Emulator Suite. The debug function has no effect in production.Debug logfile entries are prepended by a string identifying the Rules language data type of the log output (for example, string_value, map_value).Calls to debug can be nested.Currently, the debug feature does not support the concept of logging levels (for example, INFO, WARN, ERROR).
You can also refer to the stackoverflow case where Kiana and Daniel have provided a brief explanation on how logs older than 1 month got disabled automatically.
You can see it directly within the Firebase console. When trying to choose the timestamp for the logs, logs older than 1 month are disabled, which means are
automatically deleted.
You can refer to the documentation for getting an understanding of how Query language is used to filter logs in the Emulator suite UI.
Currently, there's no way to change the location since it's hard coded: https://github.com/firebase/firebase-tools/blob/c0f7acc80e8c4c2d174f97c5c41d6114e192fd23/src/emulator/downloadableEmulators.ts#L205

Why do I get an error when deploying a shiny app?

When I try to publish my ShinyApp with shinyapps.io,
I keep getting the following error message: 'Application mode static requires at least one document'.
Here are some of the fixes, I've implemented:
create a different directory with all dependent files and a copy of the R-script.
re-created custom functions from my local environment within the app
Furthermore, in 'read.csv' I refer to the files directly without specifying the directory, in case this might be the culprit.
Do you have any idea, what the issue might be?

Other unrelated apps listed in google-services.json for no apparent reason

Anyone knows why the google-services.json for a particular app when downloaded from the console contains details related to other unconnected apps that a developer might have in their firebase account? It makes no sense to list them all in this json used by a totally unrelated app. What's the reasoning behind Google/Firebase doing so and if and how the json can be cleaned up to just have only the data needed for the relevant app?
That's just the way it works. The multiple apps in that file correspond to the multiple apps that you added to the Firebase project.
The idea with putting them all in the same file is that you can use that one file in each of your app builds that are tied to the same project. On Android, sometimes developers have multiple flavors of app builds, each one with a different application ID. In that case, the Firebase plugin will select the correct app from the json with no additional work required.
Having more apps in the file doesn't hurt your build at all. As I mentioned, the gradle plugin will select the correct app from the list using its ID. The others are ignored. There is no need to clean anything up.
If you delete an app from your project using the Firebase console, you can download a new json, and that should no longer have the deleted app in it.
If you are having a specific problem or error that you think is related to the fact that multiple apps are listed, please file an issue with Firebase support, along with reproduction steps.

Is it possible to fetch and use a file from cloud storage at when deploying a cloud function

I have a firebase function that makes use of a SQLite database (read-only) which is currently uploaded along with the function.
The problem is that the db file is quite large and gets uploaded every time the function is changed. Is there a way to fetch this file from cloud storage during the installation process (during firebase deploy) - without hard-coding the URL in the source files?
What you're trying to do is problematic because your code running in Cloud Functions may actually be running on any number of server instances, determined by the load on your project. As such, downloading a file once at the time of deployment isn't going to naturally affect all the instances that maybe created or destroyed at any given moment.
It's far better to keep doing what you're doing, and include your extra data during deployment. When a new instance is spun up to handle events for your function, the file will be immediately ready to help service requests.

Execute internal code on build

Background
In an ASP.NET site, I'm using a code documentation tool called Nocco. Nocco is a command line tool that you explicitly run on a particular code file to output an HTML rendered version of that code and it's documentation. I've currently setup some code in my Global_asax.Application_Start method to crawl through a couple directories and process all the code files in each directory.
Problem
Ultimately, putting it in Global_asax.Applicaton_Start means that it is building the Nocco documentation, which takes ~1 seconds per file, at the beginning of each session - not only once per deployment. This seems inefficient and an ultimate waste of the user's time while the page is loading.
Question
Is it possible to execute code internal to the ASP.NET application (such as a class method) as a post build event? I know that I could convert this part of my setup to a standalone application or even a batch script, but I've had this question for other circumstances as well and have wondered whether or not it's possible.
You could do your generation in Warm up script, here is the link for IIS 7.5
http://blogs.iis.net/thomad/archive/2009/10/14/now-available-the-iis-7-5-application-warm-up-module.aspx
or you can exclude code documentation functionality in separate assembly and include it in standalone app and call it as a external command from project Build events

Resources