Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ $ bunx --bun srvx

| Example | Source | Try |
| ---------------- | ------------------------------------------------------------------------------------------ | -------------------------------------------------------------------- |
| `aws-lambda` | [examples/aws-lambda](https://github.com/h3js/srvx/tree/main/examples/aws-lambda/) | `npx giget gh:h3js/srvx/examples/aws-lambda srvx-aws-lambda` |
| `elysia` | [examples/elysia](https://github.com/h3js/srvx/tree/main/examples/elysia/) | `npx giget gh:h3js/srvx/examples/elysia srvx-elysia` |
| `express` | [examples/express](https://github.com/h3js/srvx/tree/main/examples/express/) | `npx giget gh:h3js/srvx/examples/express srvx-express` |
| `h3` | [examples/h3](https://github.com/h3js/srvx/tree/main/examples/h3/) | `npx giget gh:h3js/srvx/examples/h3 srvx-h3` |
Expand Down
1 change: 1 addition & 0 deletions build.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export default defineBuildConfig({
"cloudflare",
"generic",
"service-worker",
"aws-lambda",
].map((adapter) => `src/adapters/${adapter}.ts`),
],
rolldown: {
Expand Down
1 change: 1 addition & 0 deletions docs/1.guide/1.index.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ bun run server.mjs

| Example | Source | Try |
| ---------------- | ------------------------------------------------------------------------------------------ | -------------------------------------------------------------------- |
| `aws-lambda` | [examples/aws-lambda](https://github.com/h3js/srvx/tree/main/examples/aws-lambda/) | `npx giget gh:h3js/srvx/examples/aws-lambda srvx-aws-lambda` |
| `elysia` | [examples/elysia](https://github.com/h3js/srvx/tree/main/examples/elysia/) | `npx giget gh:h3js/srvx/examples/elysia srvx-elysia` |
| `express` | [examples/express](https://github.com/h3js/srvx/tree/main/examples/express/) | `npx giget gh:h3js/srvx/examples/express srvx-express` |
| `h3` | [examples/h3](https://github.com/h3js/srvx/tree/main/examples/h3/) | `npx giget gh:h3js/srvx/examples/h3 srvx-h3` |
Expand Down
29 changes: 29 additions & 0 deletions docs/1.guide/5.serverless.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
---
icon: clarity:cloud-traffic-line
---

# Serverless

> Deploy to any serverless platform

`srvx` provides built-in support for serverless platforms, allowing you to deploy your applications to various serverless environments without changing your code.

### AWS Lambda

`srvx` includes an AWS Lambda adapter that enables you to run your applications on AWS Lambda. The adapter handles all the necessary transformations between AWS Lambda's event format and standard web Request/Response objects, making it seamless to run your application in a serverless environment.

To AWS Lambda adapter, you can use the `toLambdaHandler` function from the AWS Lambda adapter:

```ts
import { toLambdaHandler } from "srvx/aws-lambda";

export const handler = toLambdaHandler({
fetch(req: Request) {
return Response.json({ hello: "world!" });
},
});
```

The `toLambdaHandler` function accepts a `ServerOptions` object as its parameter (see [Server Options](/guide/options) for details). However, since this is a serverless environment, options related to the server instance like `host` and `port` are not respected and will be ignored.

You can find a complete example of AWS Lambda in the [examples/aws-lambda](https://github.com/h3js/srvx/tree/main/examples/aws-lambda) directory, which includes configuration for the Serverless Framework and demonstrates how to set up API Gateway endpoints.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
14 changes: 14 additions & 0 deletions examples/aws-lambda/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name": "srvx-examples-aws-lambda",
"version": "0.0.0",
"type": "module",
"scripts": {
"start": "serverless offline --stage local --noPrependStageInUrl --host 0.0.0.0",
"dev": "srvx"
},
"devDependencies": {
"srvx": "latest",
"serverless": "^3",
"serverless-offline": "^14.4.0"
}
}
7 changes: 7 additions & 0 deletions examples/aws-lambda/server.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { toLambdaHandler } from "srvx/aws-lambda";

export const handler = toLambdaHandler({
fetch(req: Request) {
return Response.json({ hello: "world!" });
},
});
35 changes: 35 additions & 0 deletions examples/aws-lambda/serverless.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
service: srvx-examples-aws-lambda
frameworkVersion: "3"

provider:
name: aws
runtime: nodejs20.x
region: eu-central-1
stage: local

plugins:
- serverless-offline

package:
patterns:
- dist/**

functions:
api:
handler: server.handler
events:
- http:
path: /
method: ANY
cors: true
- http:
path: /{proxy+}
method: ANY
cors: true

custom:
serverless-offline:
noPrependStageInUrl: true
httpPort: 3000
lambdaPort: 3001
host: 0.0.0.0
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"./cloudflare": "./dist/adapters/cloudflare.mjs",
"./generic": "./dist/adapters/generic.mjs",
"./service-worker": "./dist/adapters/service-worker.mjs",
"./aws-lambda": "./dist/adapters/aws-lambda.mjs",
"./cli": "./dist/cli.mjs",
"./static": "./dist/static.mjs",
"./log": "./dist/log.mjs",
Expand Down Expand Up @@ -56,13 +57,15 @@
"srvx": "link:."
},
"dependencies": {
"cookie-es": "^2.0.0"
"cookie-es": "^2.0.0",
"ufo": "^1.6.1"
},
"devDependencies": {
"@cloudflare/workers-types": "^4.20250806.0",
"@hono/node-server": "^1.18.1",
"@mitata/counters": "^0.0.8",
"@mjackson/node-fetch-server": "^0.7.0",
"@types/aws-lambda": "^8.10.152",
"@types/bun": "^1.2.19",
"@types/deno": "^2.3.0",
"@types/node": "^24.2.0",
Expand Down
Loading