Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run firebase (functions) emulator on https instead of http?

Would anyone know if there is a way to initialize a Firebase function (using emulator to debug locally) with an https address instead of the default http? I'm trying to debug a Telegram bot-related script and Telegram only allows https webhooks.

Shell output is the following:

PS C:\Users\<user>\Desktop\tmp_node\functions> firebase emulators:start --only functions
i  emulators: Starting emulators: functions
+  hub: emulator hub started at http://localhost:4400
+  functions: Using node@10 from host.
+  functions: functions emulator started at http://localhost:8443
i  functions: Watching "C:\Users\<user>\Desktop\tmp_node\functions" for Cloud Functions...
+  functions[<function name>]: http function initialized (http://localhost:8443/<endpoint>).
+  emulators: All emulators started, it is now safe to connect.

I need it to start on https://localhost:8443/ instead.

Thank you very much in advance!

like image 455
Marc Avatar asked Nov 15 '22 12:11

Marc


1 Answers

Like @bermick mentioned in the comments, ngrok is a good way to get around this until the Firebase guys give us a way to enable https on the local emulator. Here are the steps:

  1. Head over to https://ngrok.com and sign up for a free account.
  2. Download the ngrok binary file (it's the normal thing they have you download).
  3. Open the console/terminal and navigate to the folder that the ngrok binary is in.
  4. Set up your auth token by running this command with your auth token dropped in: ./ngrok authtoken [[your_token]] (the current page at https://dashboard.ngrok.com/get-started/setup will have the whole command including the token so you can just copy and paste it into the console).
  5. Start up the Firebase emulator suite if it's not already running and make a note of the port that cloud functions are running on (I assume you know how to do this if you're googling how to use https with the emulator).
  6. Back in the console, make sure that you're in the directory containing the ngrok binary and run this command (replacing 5001 with your machine's firebase functions emulator port) ./ngrok http 5001
  7. Ngrok will open a UI that shows you the forwarding https url you can hit, which will forward to your local machine. E.g. Forwarding https://xxxxxxxxx.ngrok.io -> http://localhost:5001
  8. Test out the cloud function by using the ngrok https forwarding url (remember to append the appropriate cloud function path). E.g. https://xxxxxxxxx.ngrok.io/my-project/us-central1/cloudFunctionName
like image 113
Trev14 Avatar answered Dec 25 '22 14:12

Trev14