Skip to content

Commit

Permalink
docs: added some clarification on serverless functions getting execut…
Browse files Browse the repository at this point in the history
…ed in a non-serverless environment (#9742)

Closes #9741.

---------

Co-authored-by: Dominic Saadi <dominiceliassaadi@gmail.com>
  • Loading branch information
2 people authored and Tobbe committed Jan 1, 2024
1 parent eef8436 commit e07e967
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
7 changes: 7 additions & 0 deletions docs/docs/auth/supertokens.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ yarn rw setup auth supertokens
```

This installs all the packages, writes all the files, and makes all the code modifications you need.

:::info

You may have noticed that in `api/src/functions/auth.ts` there's an import from `'supertokens-node/framework/awsLambda'`. This is fine, even if your app isn't running in a serverless environment like AWS Lambda. In "serverful" environments, Redwood automatically handles the translation between Fastify's request and reply objects and functions' AWS Lambda signature.

:::

For a detailed explanation of all the api- and web-side changes that aren't exclusive to SuperTokens, see the top-level [Authentication](../authentication.md) doc.
For now, let's focus on SuperTokens's side of things.

Expand Down
17 changes: 10 additions & 7 deletions docs/docs/serverless-functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,19 @@
description: Create, develop, and run serverless functions
---

# Serverless Functions
# Serverless Functions (API Endpoints)

<!-- `redwood.toml`&mdash;`api/src/functions` by default. -->


:::info

You can think of serverless functions as API Endpoints, and in the future we'll update the terminology used.

Originally, Redwood apps were intended to be deployed as serverless functions to AWS Lambda. Whenever a Redwood app is deployed to a "serverful" environment such as Fly or Render, a Fastify server is started and your Redwood app's functions in `api/src/functions` are automatically registered onto the server. Request adapters are also automatically configured to handle the translation between Fastify's request and reply objects to the functions' AWS Lambda signature.

:::

Redwood looks for serverless functions in `api/src/functions`. Each function is mapped to a URI based on its filename. For example, you can find `api/src/functions/graphql.js` at `http://localhost:8911/graphql`.

## Creating Serverless Functions
Expand Down Expand Up @@ -34,12 +43,6 @@ export const handler = async (event, context) => {
}
```

:::info

We call them 'serverless' but they can also be used on 'serverful' hosted environments too, such as Render or Heroku.

:::

## The handler

For a lambda function to be a lambda function, it must export a handler that returns a status code. The handler receives two arguments: `event` and `context`. Whatever it returns is the `response`, which should include a `statusCode` at the very least.
Expand Down

0 comments on commit e07e967

Please sign in to comment.