Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: added some clarification on serverless functions getting executed in a non-serverless environment #9742

Merged
merged 4 commits into from
Dec 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading