Closed roguesherlock closed 1 week ago
Here's what my api function looks like,
import { env } from "../env"
import { auth } from "./auth"
export const api = new sst.aws.Function("API", {
url: true,
streaming: true,
handler: "./packages/functions/app/api/index.handler",
environment: {
// TODO: figure out a bette way to do this
// SITE_URL: frontend.url
SITE_URL: env.SITE_URL,
RESEND_API_KEY: env.RESEND_API_KEY,
IS_LOCAL: $dev ? "true" : "false",
XATA_BRANCH: env.XATA_BRANCH ?? "dev",
XATA_API_KEY: env.XATA_API_KEY,
},
link: [auth],
})
And here's the api handler function,
const route = app
.get("/", (c) => {
return c.text("Hello, world!")
})
.get("/aws-lambda-info/", (c) => {
return c.json({
isBase64Encoded: c.env.event.isBase64Encoded,
awsRequestId: c.env.lambdaContext?.awsRequestId,
context: c.env.context?.awsRequestId,
})
})
export const handler = process.env.SST_LIVE
? handle(app)
: (streamHandle(app) as ReturnType<typeof handle>)
export type API = typeof route
Here's the url if you want check, https://lj4dxontstbdlr5lbisqa43psm0wokeu.lambda-url.us-east-1.on.aws/aws-lambda-info
This is happening to me on SST dev but not once I deploy, @roguesherlock is it the same for you?
EDIT: Fixed when disabling streaming and using the regular Hono handler
so the issue here is streaming needs to be disabled in dev mode - we'll make it so this happens automatically
streaming: !$dev
so the issue here is streaming needs to be disabled in dev mode - we'll make it so this happens automatically
streaming: !$dev
Sorry I didn't mention it earlier but I already had that when I deployed,
import { env } from "../env"
import { auth } from "./auth"
console.log("$dev =>", $dev)
export const api = new sst.aws.Function("API", {
url: true,
// TODO: Streaming is not working in sst live.
streaming: $dev ? false : true,
handler: "./packages/functions/app/api/index.handler",
environment: {
// TODO: figure out a better way to handle cyclical dependencies
// SITE_URL: frontend.url
SITE_URL: env.SITE_URL,
RESEND_API_KEY: env.RESEND_API_KEY,
IS_LOCAL: $dev ? "true" : "false",
XATA_BRANCH: env.XATA_BRANCH ?? "dev",
XATA_API_KEY: env.XATA_API_KEY,
OPENAI_API_KEY: env.OPENAI_API_KEY,
},
architecture: "arm64",
logging: {
retention: "1 week",
},
link: [auth],
})
This is happening to me on SST dev but not once I deploy, @roguesherlock is it the same for you?
EDIT: Fixed when disabling streaming and using the regular Hono handler
nah unfortunately it happens to me on prod too :(
Basically if you run any server inside an aws function like say hono, it seems to wrap the response of the server inside a another response with its body being the response of the server.
For example here's the response I get in dev mode,
And here's the expected response for an api response,
Note that it works correctly in prod.Edit: I didn't test this properly. It looks like it doesn't work in prod either