meds
meds

Reputation: 22926

firebase serve and debugging functions?

I ran

firebase serve --only-functions

Then ran

functions inspect addMessage

So I could debug the addMessage function. Debugging however did not work.

Running

firebase deploy addMessage --trigger-http firebase inspect addMessage

Did work and allow me to debug but it doesn't seem to support hot reloading.

Is it possible to have hot reloading and debugging working at the same time?

My index.js:

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

// The Firebase Admin SDK to access the Firebase Realtime Database.
const admin = require('firebase-admin');
admin.initializeApp();

exports.addMessage = functions.https.onRequest((req, res) => {
    // Grab the text parameter.
    const original = "123";//req.query.text;
    // Push the new message into the Realtime Database using the Firebase Admin SDK.
    return admin.database().ref('/messages').push({original: original}).then((snapshot) => {
      // Redirect with 303 SEE OTHER to the URL of the pushed object in the Firebase console.
      return res.redirect(303, snapshot.ref.toString());
    });
  });

Upvotes: 5

Views: 2546

Answers (2)

Myk Willis
Myk Willis

Reputation: 12879

As of firebase-tools v7.11.0, the Firebase emulator now supports attaching a debugger with the --inspect-functions option. This answer shows WebStorm-specific instructions that can be easily adapted to other debuggers.

Upvotes: 1

jimmont
jimmont

Reputation: 2544

try: ndb firebase serve

debugger breakpoints are hit with stack traces visible, note it's a little slow so give the debugger time to instrument the child processes

Additionally I was able to debug cloud functions in isolation using (caps for removed values):

GCLOUD_PROJECT=THE-FIREBASE-PROJECT node --inspect-brk /path/to/functions-framework --target FUNCTION-NAME --port=5000

where functions-framework simply expands to the full path for the installed functions-framework (global in my case) from the working directory where the index.js file is for the target functions.

Alternately when or where the FIREBASE_CONFIG is needed try this format adjusted to fit: FIREBASE_CONFIG="{\"databaseURL\":\"https://YOUR-FIREBASE-PROJECT.firebaseio.com\",\"storageBucket\":\"YOUR-FIREBASE-PROJECT.appspot.com\",\"projectId\":\"YOUR-FIREBASE-PROJECT\"}

Upvotes: 3

Related Questions