Skip to content
This repository has been archived by the owner on Oct 21, 2024. It is now read-only.

Commit

Permalink
docs: hono streaming
Browse files Browse the repository at this point in the history
  • Loading branch information
jayair committed Sep 23, 2024
1 parent c9370a8 commit cada5f7
Show file tree
Hide file tree
Showing 6 changed files with 102 additions and 0 deletions.
3 changes: 3 additions & 0 deletions examples/aws-hono-steam/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

# sst
.sst
14 changes: 14 additions & 0 deletions examples/aws-hono-steam/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { Hono } from "hono";
import { streamText } from "hono/streaming";
import { handle, streamHandle } from "hono/aws-lambda";

const app = new Hono()
.get("/", (c) => {
return streamText(c, async (stream) => {
await stream.writeln("Hello");
await stream.sleep(3000);
await stream.writeln("World");
})
});

export const handler = process.env.SST_LIVE ? handle(app) : streamHandle(app);
16 changes: 16 additions & 0 deletions examples/aws-hono-steam/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "aws-hono-stream",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"hono": "^4.6.2",
"sst": "latest"
}
}
14 changes: 14 additions & 0 deletions examples/aws-hono-steam/sst-env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/* This file is auto-generated by SST. Do not edit. */
/* tslint:disable */
/* eslint-disable */
import "sst"
export {}
declare module "sst" {
export interface Resource {
"Hono": {
"name": string
"type": "sst.aws.Function"
"url": string
}
}
}
54 changes: 54 additions & 0 deletions examples/aws-hono-steam/sst.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/// <reference path="./.sst/platform/config.d.ts" />

/**
* ## AWS Hono streaming
*
* An example on how to enable streaming for Lambda functions using Hono.
*
* ```ts title="sst.config.ts"
* {
* streaming: true
* }
* ```
*
* While `sst dev` doesn't support streaming, we can conditionally enable it on deploy.
*
* ```ts title="index.ts"
* export const handler = process.env.SST_LIVE ? handle(app) : streamHandle(app);
* ```
*
* This will return the standard handler for `sst dev`.
*
* :::note
* Streaming is currently not supported in `sst dev`.
* :::
*
* To test this in your terminal, use the `curl` command with the `--no-buffer` option.
*
* ```bash "--no-buffer"
* curl --no-buffer https://u3dyblk457ghskwbmzrbylpxoi0ayrbb.lambda-url.us-east-1.on.aws
* ```
*
* Here we are using a Function URL directly because API Gateway doesn't support streaming.
*
*/
export default $config({
app(input) {
return {
name: "aws-hono-stream",
home: "aws",
removal: input?.stage === "production" ? "retain" : "remove",
};
},
async run() {
const hono = new sst.aws.Function("Hono", {
url: true,
streaming: true,
timeout: "15 minutes",
handler: "index.handler",
});
return {
api: hono.url,
};
},
});
1 change: 1 addition & 0 deletions examples/aws-hono-steam/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}

0 comments on commit cada5f7

Please sign in to comment.