Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cloud Functions for Firebase with custom HTTP path

Is there a way of defining the HTTP path (after the first '/') to access a Cloud Function for Firebase?

What I'm tying to achieve is to create a rest-like path system to access the functions.

I have a GitHub with my project if there is any doubts.

like image 317
Pedro Ferreira Ramos Avatar asked Apr 03 '17 23:04

Pedro Ferreira Ramos


1 Answers

The cloudfunctions.net domain will route all traffic beginning with a function name to that function. So, for example, you could do this with a standard Express app:

var functions = require('firebase-functions');
var express = require('express');
var app = express();

app.post('/bar', (req, res) => {
  res.end('bar');
});

app.get('/foo', (req, res) => {
  res.end('foo');
});

exports.myFunc = functions.https.onRequest(app);

The above will allow you to make requests to /myFunc/foo and /myFunc/bar and handle them separately. One thing to note is that currently if you pass an Express app there will be an error if you try to access your function at /myFunc, instead needing to make your request to /myFunc/ (with a trailing slash).

like image 88
Michael Bleigh Avatar answered Sep 30 '22 14:09

Michael Bleigh