简体   繁体   中英

Firebase Functions and Autodesk Forge integration

I have a problem with a fetch request inside Firebase Functions for the Autodesk Forge Token.

Here is the error that is showing on functions registrations:

FetchError: request to https://developer.api.autodesk.com/authentication/v1/authenticate failed,

reason: getaddrinfo EAI_AGAIN developer.api.autodesk.com:443
    at ClientRequest.<anonymous> (/srv/node_modules/node-fetch/lib/index.js:1455:11)
    at emitOne (events.js:116:13)
    at ClientRequest.emit (events.js:211:7)
    at TLSSocket.socketErrorListener (_http_client.js:401:9)
    at emitOne (events.js:116:13)
    at TLSSocket.emit (events.js:211:7)
    at emitErrorNT (internal/streams/destroy.js:66:8)
    at _combinedTickCallback (internal/process/next_tick.js:139:11)
    at process._tickDomainCallback (internal/process/next_tick.js:219:9)

I have already tried inserting the Forge API inside my react js project, and figure it out it would be a CORS problems.

  const snapshot = change.after;
  console.log(snapshot)
  const api = "https://developer.api.autodesk.com/authentication/v1/authenticate"

  const search = () =>
    fetch(`${api}`, {
      method: 'POST',
      headers: {
        'Content-Type': 'application/x-www-form-urlencoded'
      },
      body: JSON.stringify(`client_id=${process.env.REACT_APP_FORGE_CLIENT_ID}&client_secret=${process.env.REACT_APP_FORGE_CLIENT_SECRET}&grant_type=client_credentials&scope=data:read`)
    }).then(res => res.json())

  search().then((res) => {
    const data = res
    return snapshot.ref.parent.child('token').set(data);
  })
})

Since Firebase Functions runs in the GCD backend CORS does not really come into play ...

You must be on the free plan - getaddrinfo EAI_AGAIN indicates a DNS lookup timeout and is due to the limitations of the free tier where outbound networking is limited to within Google services. Upgrade your plan to Flame or Blaze .

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