Skip to content

FR: Support for overriding Firebase Cloud Messaging Endpoint  #379

@sahejsingh

Description

@sahejsingh

Describe your environment

  • Firebase Product: firebase cloud messaging (fcm) service

GO Service trying to send message to FCM.

Step 3: Describe the problem

Unable to do local integration testing with FCM.

Steps to reproduce:

  • Integrate with FCM Go Library
  • use messaging.Send() to send the message

At this point I would like to verify if the message has been received properly and I am handling the response properly as well.

As there is no fcm emulator available yet, I wrote a simple HTTP server that can handle the Send API. Now to make this work in local environment, I want to override the messagingEndpoint (https://github.com/firebase/firebase-admin-go/blob/master/messaging/messaging.go#L947) by using the https://godoc.org/google.golang.org/api/option#WithEndpoint option.

Relevant Code:

Here is the proposed fix:

Introduced ep below in the NewClient method defined at https://github.com/firebase/firebase-admin-go/blob/master/messaging/messaging.go#L911

// NewClient creates a new instance of the Firebase Cloud Messaging Client.
//
// This function can only be invoked from within the SDK. Client applications should access the
// the messaging service through firebase.App.
func NewClient(ctx context.Context, c *internal.MessagingConfig) (*Client, error) {
	if c.ProjectID == "" {
		return nil, errors.New("project ID is required to access Firebase Cloud Messaging client")
	}

	hc, ep, err := transport.NewHTTPClient(ctx, c.Opts...)
	if err != nil {
		return nil, err
	}

	if ep == "" {
		ep = messagingEndpoint
	}

	return &Client{
		fcmClient: newFCMClient(hc, ep, c),
		iidClient: newIIDClient(hc),
	}, nil
}

Clients of this code then call it like so

var opts []option.ClientOption
        
if emulate {
   opts = append(opts, option.WithEndpoint("http://localhost:3000/v1"))
}

app, err := firebase.NewApp(ctx, conf, opts...)

Question

Is this approach ok?

If yes, I am happy to raise a PR to make this option work.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions