简体   繁体   中英

Unexpected Error when deploying braintree server on firebase functions

I'm facing a problem with Braintree Server Node SDK on Firebase functions .

But the weird part is that it works well on my local server (using firebase serve locally).

On firebase, the app just return an unexpectedError on the error object without specifying an understandable error message.

I even tried to set the timeout on the gateway object to a high value but the problem still occurs.

Here's the part of my server code that manage the token generation:

const functions = require("firebase-functions");
const express = require("express");
const braintree = require("braintree");

var gateway = braintree.connect({
  environment: braintree.Environment.Sandbox,
  merchantId: "************",
  publicKey: "************",
  privateKey: "************"
});

app.get("/generate_token", function (req, res) {
  gateway.clientToken.generate({}, function (err, response) {
    if(response)
      res.send({error: false, token: response.clientToken});
    else
      res.send({error: true, errorObj: err, response: response});
  });
});

Running this code locally return a correct result:

{"error": false, "token": "*********"}

But deploying on firebase and running it return an error:

{
  "error": true,
  "errorObj": {
    "name": "unexpectedError",
    "type": "unexpectedError"
  }
}

For Firebase projects on the free tier (Spark), outgoing socket connections to non-Google controlled endpoints are blocked. This is to prevent automated abuse. Your project will need to be upgraded to the Blaze plan to enable outgoing connections. The cost of this for the purpose of development will probably be negligible, but you should still check the pricing page before you upgrade.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM