-
Notifications
You must be signed in to change notification settings - Fork 6
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
Hosting Adapter AWS Lambda #30
Comments
That would be awesome @aheissenberger! Currently the only adapter in existence is for Vercel. Creating the To implement another adapter, there are some dependencies regarding moving any code from the Vercel adapter either into the core package or into a shared package for adapters, like What I have in mind already:
The adapters for The entrypoint for the Vercel serverless function is just using the middleware mode of the framework at https://github.com/lazarv/react-server/blob/main/packages/react-server-adapter-vercel/functions/index.mjs. I think something similar will be ok for AWS too, but surely needs more than this. |
I looked at the existing code and the problems are:
Here is a code I used to wrap the vike.dev middleware for AWS Lambda: import { existsSync } from "node:fs";
import awsLambdaAdapter from "@hattip/adapter-aws-lambda";
import { walk } from "@hattip/walk";
import type { FileInfo } from "@hattip/walk";
import { createStaticMiddleware } from "@hattip/static";
import { createFileReader } from "@hattip/static/fs";
import hattipHandler from "@batijs/hattip/hattip-entry";
import type { Handler, APIGatewayProxyResultV2, APIGatewayProxyEventV2 } from "aws-lambda";
const root = new URL("./dist/client", import.meta.url);
const staticRootExists = existsSync(root);
const files = staticRootExists ? walk(root) : new Map<string, FileInfo>();
const staticMiddleware = staticRootExists
? createStaticMiddleware(files, createFileReader(root), {
urlRoot: "/",
})
: undefined;
const awsHandler = awsLambdaAdapter((ctx) => {
if (hattipHandler === undefined) throw new Error("hattipHandler is undefined");
if (staticMiddleware === undefined) return hattipHandler(ctx);
return staticMiddleware(ctx) || hattipHandler(ctx);
});
export const handler: Handler<APIGatewayProxyEventV2, APIGatewayProxyResultV2> = awsHandler; The deployment tool I think I will need your help to get the restructuring of (1.) done. |
Regarding dependency management I think that the It might would be a good approach in case of AWS sst or cdk to have a generated output that the developer can integrate into an existing sst or cdk setup, but also provide a simple default for easy deployment.
Yes I can prepare everything for this work to get started, I'll prioritize it up. |
Did you got this working? This only works for client side routing and not for server side routing - at least I never got that working ;-) here is what Vike.dev is using to abstract the adapters: I am not sure if this kind of abstraction is really needed compared to choose one middleware and stick with it. Based on numbers its h3 which is used most and second by hono(hattip benchmarks) as the speed king but I am not an expert in this field. For people using your framework it should not matter what you choose to use as long as there is an adapter for the most used deployment platforms and based on my experience it is not hard to create a new one if the platform is not directly supported. I have never used When I looked at For the start I would provide a CDK Stack as its only javascript and does not need a native binary to be installed as it is the case with |
You can also just try to copy together a production build of a simple example (even just a Hello World!) and deploy it manually to AWS Lambda by using any tech to be aware of any pain points which now exists, using https://github.com/lazarv/react-server/blob/main/packages/react-server/lib/start/node.mjs and https://github.com/lazarv/react-server/blob/main/packages/react-server/lib/start/create-server.mjs as a starting point to create a Lamda handler. The only necessary steps in this are:
When using a build which not included any client components, none of the static files are needed to make this work. I would suggest a Hello World! with a Following this there should be an AWS Lambda handler as result which only needs some refactor to include it in the framework similar to Supporting Edge runtimes like Lambda@Edge or Vercel Edge is a feature I'm not working right now at all. I consider it nice to have for now. It needs major architectural work in the framework, starting with running router middlewares (like in Next.js) on the Edge.
The issue with the |
Prepares work for #30 Adds `@lazarv/react-server-adapter-core` package to implement the Deployment Adapter API Updates Vercel adapter to use the Adapter API
Hi @aheissenberger! If you're still interested, then you can use |
still interested but was busy with work 😄 |
Description
I would like to help to implement the Adapter as I have done this for WAKU and Vike.dev (BATI.dev).
Suggested solution
using SST or CDK.
Alternative
No response
Additional context
Is there any other example which targets a node environment except for the Vercel adapter?
Validations
The text was updated successfully, but these errors were encountered: