question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

RFC - API side utilities to help work with functions

See original GitHub issue

In recent projects, I have been repeating code to do some common tasks related to api side functions and it could be helpful to add this utilities to the RedwoodJS api package:

  1. Get the Netlify functions endpoint regardless of branch.

You will need to know the function endpoint url when invoking a background function from a RW api service – especially when you have multiple environments or deploy previews.

Something like:

export const siteUrl = () => {
  const defaultUrl = `http://localhost:8910`

  try {
    const netlifySignature = context.clientContext?.custom?.netlify

    if (netlifySignature === undefined) {
      throw new Error('Undefined signature')
    }

    const signature = Buffer.from(netlifySignature, 'base64').toString('ascii')
    const decoded = JSON.parse(signature)

    if (decoded['site_url']) {
      return decoded['site_url']
    } else {
      throw new Error('Could not find site_url in jwt')
    }
  } catch (error) {
    console.error(`Unable to decode Netlify token from context: ${error}`)
    return defaultUrl
  }
}

const functionsUrl = ({ url }) => {
  return `${url}/.netlify/functions`
}
  1. Sign function/background functions like webhooks to ensure these are not 100% open to execution by verifying the signature.

See https://github.com/quirrel-dev/secure-webhooks for some examples to sign a payload and verify it.

One might use JWS instead to sign the payload (the above uses a different technique).

  1. A utility to wrap signing and sending in a single method

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
dthyressoncommented, May 20, 2021

@jtoar Honestly, I forgot I wrote up this issue. The new webhook signature verifiers supports the features I needed when I wrote up this issue, so I think we can close this out.

0reactions
jtoarcommented, May 20, 2021

Webhook helpers have been added! #1843

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to use RFC adapter in SAP Cloud Platform Integration ...
The RFC interface system enables function calls between two SAP systems, or between an SAP system and an external system.
Read more >
The RFC API
This documentation describes how to use RFC (Remote Function Call) from outside an SAP. System, that is, how to write your own RFC...
Read more >
rfcs/0626-invoke-helper.md at master · emberjs/rfcs
This RFC proposes a new API, invokeHelper , which can be used to invoke a helper definition, creating an instance of the helper...
Read more >
Session Traversal Utilities for NAT (STUN) RFC 5389
Abstract Session Traversal Utilities for NAT (STUN) is a protocol that serves as a tool for other protocols in dealing with Network Address...
Read more >
RFC 8353: Generic Security Service API Version 2: Java ...
1. getInstance public static GSSManager getInstance() Returns the default GSSManager implementation. · 2. getMechs public abstract Oid[] getMechs() Returns an ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found