diff --git a/examples/app-pages-router/open-next.config.ts b/examples/app-pages-router/open-next.config.ts
new file mode 100644
index 000000000..6b4345ecf
--- /dev/null
+++ b/examples/app-pages-router/open-next.config.ts
@@ -0,0 +1,8 @@
+const config = {
+  functions: {
+    default: {},
+  },
+  buildCommand: "npx turbo build",
+};
+
+module.exports = config;
diff --git a/examples/app-router/open-next.config.ts b/examples/app-router/open-next.config.ts
new file mode 100644
index 000000000..423ca55ef
--- /dev/null
+++ b/examples/app-router/open-next.config.ts
@@ -0,0 +1,12 @@
+const config = {
+  functions: {
+    default: {
+      override: {
+        wrapper: "aws-lambda-streaming",
+      },
+    },
+  },
+  buildCommand: "npx turbo build",
+};
+
+module.exports = config;
diff --git a/examples/pages-router/open-next.config.ts b/examples/pages-router/open-next.config.ts
new file mode 100644
index 000000000..6b4345ecf
--- /dev/null
+++ b/examples/pages-router/open-next.config.ts
@@ -0,0 +1,8 @@
+const config = {
+  functions: {
+    default: {},
+  },
+  buildCommand: "npx turbo build",
+};
+
+module.exports = config;
diff --git a/packages/open-next/package.json b/packages/open-next/package.json
index 83732ed3b..c19010d90 100644
--- a/packages/open-next/package.json
+++ b/packages/open-next/package.json
@@ -3,7 +3,7 @@
     "access": "public"
   },
   "name": "open-next",
-  "version": "2.3.2",
+  "version": "3.0.0-alpha.2",
   "bin": {
     "open-next": "./dist/index.js"
   },
diff --git a/packages/open-next/src/adapters/cache.ts b/packages/open-next/src/adapters/cache.ts
index 437f3d8c8..4cf40f58a 100644
--- a/packages/open-next/src/adapters/cache.ts
+++ b/packages/open-next/src/adapters/cache.ts
@@ -1,21 +1,6 @@
-import {
-  BatchWriteItemCommand,
-  DynamoDBClient,
-  QueryCommand,
-} from "@aws-sdk/client-dynamodb";
-import {
-  DeleteObjectsCommand,
-  GetObjectCommand,
-  ListObjectsV2Command,
-  PutObjectCommand,
-  PutObjectCommandInput,
-  S3Client,
-} from "@aws-sdk/client-s3";
-import path from "path";
-
-import { MAX_DYNAMO_BATCH_WRITE_ITEM_COUNT } from "./constants.js";
+import { IncrementalCache } from "../cache/incremental/types.js";
+import { TagCache } from "../cache/tag/types.js";
 import { debug, error, warn } from "./logger.js";
-import { chunk } from "./util.js";
 
 interface CachedFetchValue {
   kind: "FETCH";
@@ -69,6 +54,14 @@ type IncrementalCacheValue =
   | CachedFetchValue
   | CachedRouteValue;
 
+type IncrementalCacheContext = {
+  revalidate?: number | false | undefined;
+  fetchCache?: boolean | undefined;
+  fetchUrl?: string | undefined;
+  fetchIdx?: number | undefined;
+  tags?: string[] | undefined;
+};
+
 interface CacheHandlerContext {
   fs?: never;
   dev?: boolean;
@@ -87,36 +80,6 @@ interface CacheHandlerValue {
   value: IncrementalCacheValue | null;
 }
 
-type Extension = "cache" | "fetch";
-
-interface Meta {
-  status?: number;
-  headers?: Record<string, undefined | string | string[]>;
-}
-type S3CachedFile =
-  | {
-      type: "redirect";
-      props?: Object;
-      meta?: Meta;
-    }
-  | {
-      type: "page";
-      html: string;
-      json: Object;
-      meta?: Meta;
-    }
-  | {
-      type: "app";
-      html: string;
-      rsc: string;
-      meta?: Meta;
-    }
-  | {
-      type: "route";
-      body: string;
-      meta?: Meta;
-    };
-
 /** Beginning single backslash is intentional, to look for the dot + the extension. Do not escape it again. */
 const CACHE_EXTENSION_REGEX = /\.(cache|fetch)$/;
 
@@ -124,31 +87,21 @@ export function hasCacheExtension(key: string) {
   return CACHE_EXTENSION_REGEX.test(key);
 }
 
-// Expected environment variables
-const {
-  CACHE_BUCKET_NAME,
-  CACHE_BUCKET_KEY_PREFIX,
-  CACHE_DYNAMO_TABLE,
-  NEXT_BUILD_ID,
-} = process.env;
-
 declare global {
-  var S3Client: S3Client;
-  var dynamoClient: DynamoDBClient;
+  var incrementalCache: IncrementalCache;
+  var tagCache: TagCache;
   var disableDynamoDBCache: boolean;
   var disableIncrementalCache: boolean;
   var lastModified: number;
 }
 
 export default class S3Cache {
-  private client: S3Client;
-  private dynamoClient: DynamoDBClient;
-  private buildId: string;
+  private client: IncrementalCache;
+  private tagClient: TagCache;
 
   constructor(_ctx: CacheHandlerContext) {
-    this.client = globalThis.S3Client;
-    this.dynamoClient = globalThis.dynamoClient;
-    this.buildId = NEXT_BUILD_ID!;
+    this.client = globalThis.incrementalCache;
+    this.tagClient = globalThis.tagCache;
   }
 
   public async get(key: string, options?: boolean | { fetchCache?: boolean }) {
@@ -165,21 +118,22 @@ export default class S3Cache {
   async getFetchCache(key: string) {
     debug("get fetch cache", { key });
     try {
-      const { Body, LastModified } = await this.getS3Object(key, "fetch");
-      const lastModified = await this.getHasRevalidatedTags(
+      const { value, lastModified } = await this.client.get(key, true);
+      // const { Body, LastModified } = await this.getS3Object(key, "fetch");
+      const _lastModified = await this.tagClient.getLastModified(
         key,
-        LastModified?.getTime(),
+        lastModified,
       );
-      if (lastModified === -1) {
+      if (_lastModified === -1) {
         // If some tags are stale we need to force revalidation
         return null;
       }
 
-      if (Body === null) return null;
+      if (value === undefined) return null;
 
       return {
-        lastModified,
-        value: JSON.parse((await Body?.transformToString()) ?? "{}"),
+        lastModified: _lastModified,
+        value: value,
       } as CacheHandlerValue;
     } catch (e) {
       error("Failed to get fetch cache", e);
@@ -189,23 +143,27 @@ export default class S3Cache {
 
   async getIncrementalCache(key: string): Promise<CacheHandlerValue | null> {
     try {
-      const { Body, LastModified } = await this.getS3Object(key, "cache");
-      const cacheData = JSON.parse(
-        (await Body?.transformToString()) ?? "{}",
-      ) as S3CachedFile;
-      const meta = cacheData.meta;
-      const lastModified = await this.getHasRevalidatedTags(
+      const { value: cacheData, lastModified } = await this.client.get(
         key,
-        LastModified?.getTime(),
+        false,
       );
-      if (lastModified === -1) {
+      // const { Body, LastModified } = await this.getS3Object(key, "cache");
+      // const cacheData = JSON.parse(
+      //   (await Body?.transformToString()) ?? "{}",
+      // ) as S3CachedFile;
+      const meta = cacheData?.meta;
+      const _lastModified = await this.tagClient.getLastModified(
+        key,
+        lastModified,
+      );
+      if (_lastModified === -1) {
         // If some tags are stale we need to force revalidation
         return null;
       }
-      globalThis.lastModified = lastModified;
-      if (cacheData.type === "route") {
+      globalThis.lastModified = _lastModified;
+      if (cacheData?.type === "route") {
         return {
-          lastModified: LastModified?.getTime(),
+          lastModified: _lastModified,
           value: {
             kind: "ROUTE",
             body: Buffer.from(cacheData.body ?? Buffer.alloc(0)),
@@ -213,9 +171,9 @@ export default class S3Cache {
             headers: meta?.headers,
           },
         } as CacheHandlerValue;
-      } else if (cacheData.type === "page" || cacheData.type === "app") {
+      } else if (cacheData?.type === "page" || cacheData?.type === "app") {
         return {
-          lastModified: LastModified?.getTime(),
+          lastModified: _lastModified,
           value: {
             kind: "PAGE",
             html: cacheData.html,
@@ -225,9 +183,9 @@ export default class S3Cache {
             headers: meta?.headers,
           },
         } as CacheHandlerValue;
-      } else if (cacheData.type === "redirect") {
+      } else if (cacheData?.type === "redirect") {
         return {
-          lastModified: LastModified?.getTime(),
+          lastModified: _lastModified,
           value: {
             kind: "REDIRECT",
             props: cacheData.props,
@@ -243,68 +201,81 @@ export default class S3Cache {
     }
   }
 
-  async set(key: string, data?: IncrementalCacheValue): Promise<void> {
+  async set(
+    key: string,
+    data?: IncrementalCacheValue,
+    ctx?: IncrementalCacheContext,
+  ): Promise<void> {
     if (globalThis.disableIncrementalCache) {
       return;
     }
     if (data?.kind === "ROUTE") {
       const { body, status, headers } = data;
-      this.putS3Object(
+      await this.client.set(
         key,
-        "cache",
-        JSON.stringify({
+        {
           type: "route",
           body: body.toString("utf8"),
           meta: {
             status,
             headers,
           },
-        } as S3CachedFile),
+        },
+        false,
       );
     } else if (data?.kind === "PAGE") {
       const { html, pageData } = data;
       const isAppPath = typeof pageData === "string";
-      this.putS3Object(
-        key,
-        "cache",
-        JSON.stringify({
-          type: isAppPath ? "app" : "page",
-          html,
-          rsc: isAppPath ? pageData : undefined,
-          json: isAppPath ? undefined : pageData,
-          meta: { status: data.status, headers: data.headers },
-        } as S3CachedFile),
-      );
+      if (isAppPath) {
+        this.client.set(
+          key,
+          {
+            type: "app",
+            html,
+            rsc: pageData,
+          },
+          false,
+        );
+      } else {
+        this.client.set(
+          key,
+          {
+            type: "page",
+            html,
+            json: pageData,
+          },
+          false,
+        );
+      }
     } else if (data?.kind === "FETCH") {
-      await this.putS3Object(key, "fetch", JSON.stringify(data));
+      await this.client.set<true>(key, data, true);
     } else if (data?.kind === "REDIRECT") {
-      // // delete potential page data if we're redirecting
-      await this.putS3Object(
+      await this.client.set(
         key,
-        "cache",
-        JSON.stringify({
+        {
           type: "redirect",
           props: data.props,
-        } as S3CachedFile),
+        },
+        false,
       );
     } else if (data === null || data === undefined) {
-      await this.deleteS3Objects(key);
+      await this.client.delete(key);
     }
     // Write derivedTags to dynamodb
     // If we use an in house version of getDerivedTags in build we should use it here instead of next's one
     const derivedTags: string[] =
       data?.kind === "FETCH"
-        ? data.data.tags ?? []
+        ? ctx?.tags ?? []
         : data?.kind === "PAGE"
         ? data.headers?.["x-next-cache-tags"]?.split(",") ?? []
         : [];
     debug("derivedTags", derivedTags);
     // Get all tags stored in dynamodb for the given key
     // If any of the derived tags are not stored in dynamodb for the given key, write them
-    const storedTags = await this.getTagsByPath(key);
+    const storedTags = await this.tagClient.getByPath(key);
     const tagsToWrite = derivedTags.filter((tag) => !storedTags.includes(tag));
     if (tagsToWrite.length > 0) {
-      await this.batchWriteDynamoItem(
+      await this.tagClient.writeTags(
         tagsToWrite.map((tag) => ({
           path: key,
           tag: tag,
@@ -319,219 +290,14 @@ export default class S3Cache {
     }
     debug("revalidateTag", tag);
     // Find all keys with the given tag
-    const paths = await this.getByTag(tag);
+    const paths = await this.tagClient.getByTag(tag);
     debug("Items", paths);
     // Update all keys with the given tag with revalidatedAt set to now
-    await this.batchWriteDynamoItem(
+    await this.tagClient.writeTags(
       paths?.map((path) => ({
         path: path,
         tag: tag,
       })) ?? [],
     );
   }
-
-  // DynamoDB handling
-
-  private async getTagsByPath(path: string) {
-    try {
-      if (disableDynamoDBCache) return [];
-      const result = await this.dynamoClient.send(
-        new QueryCommand({
-          TableName: CACHE_DYNAMO_TABLE,
-          IndexName: "revalidate",
-          KeyConditionExpression: "#key = :key",
-          ExpressionAttributeNames: {
-            "#key": "path",
-          },
-          ExpressionAttributeValues: {
-            ":key": { S: this.buildDynamoKey(path) },
-          },
-        }),
-      );
-      const tags = result.Items?.map((item) => item.tag.S ?? "") ?? [];
-      debug("tags for path", path, tags);
-      return tags;
-    } catch (e) {
-      error("Failed to get tags by path", e);
-      return [];
-    }
-  }
-
-  //TODO: Figure out a better name for this function since it returns the lastModified
-  private async getHasRevalidatedTags(key: string, lastModified?: number) {
-    try {
-      if (disableDynamoDBCache) return lastModified ?? Date.now();
-      const result = await this.dynamoClient.send(
-        new QueryCommand({
-          TableName: CACHE_DYNAMO_TABLE,
-          IndexName: "revalidate",
-          KeyConditionExpression:
-            "#key = :key AND #revalidatedAt > :lastModified",
-          ExpressionAttributeNames: {
-            "#key": "path",
-            "#revalidatedAt": "revalidatedAt",
-          },
-          ExpressionAttributeValues: {
-            ":key": { S: this.buildDynamoKey(key) },
-            ":lastModified": { N: String(lastModified ?? 0) },
-          },
-        }),
-      );
-      const revalidatedTags = result.Items ?? [];
-      debug("revalidatedTags", revalidatedTags);
-      // If we have revalidated tags we return -1 to force revalidation
-      return revalidatedTags.length > 0 ? -1 : lastModified ?? Date.now();
-    } catch (e) {
-      error("Failed to get revalidated tags", e);
-      return lastModified ?? Date.now();
-    }
-  }
-
-  private async getByTag(tag: string) {
-    try {
-      if (disableDynamoDBCache) return [];
-      const { Items } = await this.dynamoClient.send(
-        new QueryCommand({
-          TableName: CACHE_DYNAMO_TABLE,
-          KeyConditionExpression: "#tag = :tag",
-          ExpressionAttributeNames: {
-            "#tag": "tag",
-          },
-          ExpressionAttributeValues: {
-            ":tag": { S: this.buildDynamoKey(tag) },
-          },
-        }),
-      );
-      return (
-        // We need to remove the buildId from the path
-        Items?.map(
-          ({ path: { S: key } }) => key?.replace(`${this.buildId}/`, "") ?? "",
-        ) ?? []
-      );
-    } catch (e) {
-      error("Failed to get by tag", e);
-      return [];
-    }
-  }
-
-  private async batchWriteDynamoItem(req: { path: string; tag: string }[]) {
-    try {
-      if (disableDynamoDBCache) return;
-      await Promise.all(
-        chunk(req, MAX_DYNAMO_BATCH_WRITE_ITEM_COUNT).map((Items) => {
-          return this.dynamoClient.send(
-            new BatchWriteItemCommand({
-              RequestItems: {
-                [CACHE_DYNAMO_TABLE ?? ""]: Items.map((Item) => ({
-                  PutRequest: {
-                    Item: {
-                      ...this.buildDynamoObject(Item.path, Item.tag),
-                    },
-                  },
-                })),
-              },
-            }),
-          );
-        }),
-      );
-    } catch (e) {
-      error("Failed to batch write dynamo item", e);
-    }
-  }
-
-  private buildDynamoKey(key: string) {
-    // FIXME: We should probably use something else than path.join here
-    // this could transform some fetch cache key into a valid path
-    return path.posix.join(this.buildId, key);
-  }
-
-  private buildDynamoObject(path: string, tags: string) {
-    return {
-      path: { S: this.buildDynamoKey(path) },
-      tag: { S: this.buildDynamoKey(tags) },
-      revalidatedAt: { N: `${Date.now()}` },
-    };
-  }
-
-  // S3 handling
-
-  private buildS3Key(key: string, extension: Extension) {
-    return path.posix.join(
-      CACHE_BUCKET_KEY_PREFIX ?? "",
-      extension === "fetch" ? "__fetch" : "",
-      this.buildId,
-      extension === "fetch" ? key : `${key}.${extension}`,
-    );
-  }
-
-  private buildS3KeyPrefix(key: string) {
-    return path.posix.join(CACHE_BUCKET_KEY_PREFIX ?? "", this.buildId, key);
-  }
-
-  private async listS3Object(key: string) {
-    const { Contents } = await this.client.send(
-      new ListObjectsV2Command({
-        Bucket: CACHE_BUCKET_NAME,
-        // add a point to the key so that it only matches the key and
-        // not other keys starting with the same string
-        Prefix: `${this.buildS3KeyPrefix(key)}.`,
-      }),
-    );
-    return (Contents ?? []).map(({ Key }) => Key) as string[];
-  }
-
-  private async getS3Object(key: string, extension: Extension) {
-    try {
-      const result = await this.client.send(
-        new GetObjectCommand({
-          Bucket: CACHE_BUCKET_NAME,
-          Key: this.buildS3Key(key, extension),
-        }),
-      );
-      return result;
-    } catch (e) {
-      warn("This error can usually be ignored : ", e);
-      return { Body: null, LastModified: null };
-    }
-  }
-
-  private putS3Object(
-    key: string,
-    extension: Extension,
-    value: PutObjectCommandInput["Body"],
-  ) {
-    return this.client.send(
-      new PutObjectCommand({
-        Bucket: CACHE_BUCKET_NAME,
-        Key: this.buildS3Key(key, extension),
-        Body: value,
-      }),
-    );
-  }
-
-  private async deleteS3Objects(key: string) {
-    try {
-      const s3Keys = (await this.listS3Object(key)).filter(
-        (key) => key && hasCacheExtension(key),
-      );
-
-      if (s3Keys.length === 0) {
-        warn(
-          `No s3 keys with a valid cache extension found for ${key}, see type CacheExtension in OpenNext for details`,
-        );
-        return;
-      }
-
-      await this.client.send(
-        new DeleteObjectsCommand({
-          Bucket: CACHE_BUCKET_NAME,
-          Delete: {
-            Objects: s3Keys.map((Key) => ({ Key })),
-          },
-        }),
-      );
-    } catch (e) {
-      error("Failed to delete cache", e);
-    }
-  }
 }
diff --git a/packages/open-next/src/adapters/config/index.ts b/packages/open-next/src/adapters/config/index.ts
index c686074fa..8592a7e2e 100644
--- a/packages/open-next/src/adapters/config/index.ts
+++ b/packages/open-next/src/adapters/config/index.ts
@@ -7,6 +7,7 @@ import {
   loadConfig,
   loadConfigHeaders,
   loadHtmlPages,
+  loadMiddlewareManifest,
   loadPrerenderManifest,
   loadPublicAssets,
   loadRoutesManifest,
@@ -17,6 +18,7 @@ export const OPEN_NEXT_DIR = path.join(__dirname, ".open-next");
 
 debug({ NEXT_DIR, OPEN_NEXT_DIR });
 
+//TODO: inject these values at build time
 export const NextConfig = loadConfig(NEXT_DIR);
 export const BuildId = loadBuildId(NEXT_DIR);
 export const HtmlPages = loadHtmlPages(NEXT_DIR);
@@ -25,3 +27,4 @@ export const RoutesManifest = loadRoutesManifest(NEXT_DIR);
 export const ConfigHeaders = loadConfigHeaders(NEXT_DIR);
 export const PrerenderManifest = loadPrerenderManifest(NEXT_DIR);
 export const AppPathsManifestKeys = loadAppPathsManifestKeys(NEXT_DIR);
+export const MiddlewareManifest = loadMiddlewareManifest(NEXT_DIR);
diff --git a/packages/open-next/src/adapters/config/util.ts b/packages/open-next/src/adapters/config/util.ts
index b0455ed53..aa11ee3b5 100644
--- a/packages/open-next/src/adapters/config/util.ts
+++ b/packages/open-next/src/adapters/config/util.ts
@@ -1,12 +1,13 @@
 import fs from "fs";
 import path from "path";
-
-import { PublicFiles } from "../../build";
 import {
+  MiddlewareManifest,
   NextConfig,
   PrerenderManifest,
   RoutesManifest,
-} from "../types/next-types";
+} from "types/next-types";
+
+import { PublicFiles } from "../../build";
 
 export function loadConfig(nextDir: string) {
   const filePath = path.join(nextDir, "required-server-files.json");
@@ -100,3 +101,9 @@ export function loadAppPathsManifestKeys(nextDir: string) {
     return cleanedKey === "" ? "/" : cleanedKey;
   });
 }
+
+export function loadMiddlewareManifest(nextDir: string) {
+  const filePath = path.join(nextDir, "server", "middleware-manifest.json");
+  const json = fs.readFileSync(filePath, "utf-8");
+  return JSON.parse(json) as MiddlewareManifest;
+}
diff --git a/packages/open-next/src/adapters/dynamo-provider.ts b/packages/open-next/src/adapters/dynamo-provider.ts
index d2e677c58..5d15e6c0c 100644
--- a/packages/open-next/src/adapters/dynamo-provider.ts
+++ b/packages/open-next/src/adapters/dynamo-provider.ts
@@ -1,20 +1,16 @@
-import {
-  BatchWriteItemCommand,
-  DynamoDBClient,
-} from "@aws-sdk/client-dynamodb";
-import { CdkCustomResourceEvent, CdkCustomResourceResponse } from "aws-lambda";
 import { readFileSync } from "fs";
 
+import { createGenericHandler } from "../core/createGenericHandler.js";
+import { resolveTagCache } from "../core/resolve.js";
 import {
   getDynamoBatchWriteCommandConcurrency,
   MAX_DYNAMO_BATCH_WRITE_ITEM_COUNT,
 } from "./constants.js";
 import { chunk } from "./util.js";
 
-const PHYSICAL_RESOURCE_ID = "dynamodb-cache";
-
-const dynamoClient = new DynamoDBClient({});
+const PHYSICAL_RESOURCE_ID = "dynamodb-cache" as const;
 
+//TODO: modify this, we should use the same format as the cache
 type DataType = {
   tag: {
     S: string;
@@ -27,62 +23,69 @@ type DataType = {
   };
 };
 
-export async function handler(
-  event: CdkCustomResourceEvent,
-): Promise<CdkCustomResourceResponse> {
-  switch (event.RequestType) {
-    case "Create":
-    case "Update":
-      return insert();
-    case "Delete":
+interface InitializationFunctionEvent {
+  type: "initializationFunction";
+  requestType: "create" | "update" | "delete";
+  resourceId: typeof PHYSICAL_RESOURCE_ID;
+}
+
+const tagCache = await resolveTagCache(
+  globalThis.openNextConfig?.initializationFunction?.tagCache,
+);
+
+export const handler = await createGenericHandler({
+  handler: defaultHandler,
+  type: "initializationFunction",
+});
+
+async function defaultHandler(
+  event: InitializationFunctionEvent,
+): Promise<InitializationFunctionEvent> {
+  switch (event.requestType) {
+    case "create":
+    case "update":
+      return insert(event.requestType);
+    case "delete":
       return remove();
   }
 }
 
-async function insert(): Promise<CdkCustomResourceResponse> {
-  const tableName = process.env.CACHE_DYNAMO_TABLE!;
-
+async function insert(
+  requestType: InitializationFunctionEvent["requestType"],
+): Promise<InitializationFunctionEvent> {
   const file = readFileSync(`dynamodb-cache.json`, "utf8");
 
   const data: DataType[] = JSON.parse(file);
 
-  const dataChunks = chunk(data, MAX_DYNAMO_BATCH_WRITE_ITEM_COUNT);
+  const parsedData = data.map((item) => ({
+    tag: item.tag.S,
+    path: item.path.S,
+    revalidatedAt: parseInt(item.revalidatedAt.N),
+  }));
 
-  const batchWriteParamsArray = dataChunks.map((chunk) => {
-    return {
-      RequestItems: {
-        [tableName]: chunk.map((item) => ({
-          PutRequest: {
-            Item: item,
-          },
-        })),
-      },
-    };
-  });
+  const dataChunks = chunk(parsedData, MAX_DYNAMO_BATCH_WRITE_ITEM_COUNT);
 
   const paramsChunks = chunk(
-    batchWriteParamsArray,
+    dataChunks,
     getDynamoBatchWriteCommandConcurrency(),
   );
 
   for (const paramsChunk of paramsChunks) {
-    await Promise.all(
-      paramsChunk.map((params) =>
-        dynamoClient.send(new BatchWriteItemCommand(params)),
-      ),
-    );
+    await Promise.all(paramsChunk.map((params) => tagCache.writeTags(params)));
   }
 
   return {
-    PhysicalResourceId: PHYSICAL_RESOURCE_ID,
-    Data: {},
+    type: "initializationFunction",
+    requestType,
+    resourceId: PHYSICAL_RESOURCE_ID,
   };
 }
 
-async function remove(): Promise<CdkCustomResourceResponse> {
+async function remove(): Promise<InitializationFunctionEvent> {
   // Do we want to actually delete anything here?
   return {
-    PhysicalResourceId: PHYSICAL_RESOURCE_ID,
-    Data: {},
+    type: "initializationFunction",
+    requestType: "delete",
+    resourceId: PHYSICAL_RESOURCE_ID,
   };
 }
diff --git a/packages/open-next/src/adapters/event-mapper.ts b/packages/open-next/src/adapters/event-mapper.ts
deleted file mode 100644
index b0a343c79..000000000
--- a/packages/open-next/src/adapters/event-mapper.ts
+++ /dev/null
@@ -1,338 +0,0 @@
-import type {
-  APIGatewayProxyEvent,
-  APIGatewayProxyEventV2,
-  APIGatewayProxyResult,
-  APIGatewayProxyResultV2,
-  CloudFrontHeaders,
-  CloudFrontRequestEvent,
-  CloudFrontRequestResult,
-} from "aws-lambda";
-
-import { debug } from "./logger.js";
-import { parseCookies } from "./util.js";
-
-export type InternalEvent = {
-  readonly type: "v1" | "v2" | "cf";
-  readonly method: string;
-  readonly rawPath: string;
-  readonly url: string;
-  readonly body: Buffer;
-  readonly headers: Record<string, string>;
-  readonly query: Record<string, string | string[]>;
-  readonly cookies: Record<string, string>;
-  readonly remoteAddress: string;
-};
-
-export type InternalResult = {
-  readonly type: "v1" | "v2" | "cf";
-  statusCode: number;
-  headers: Record<string, string | string[]>;
-  body: string;
-  isBase64Encoded: boolean;
-};
-
-export function isAPIGatewayProxyEventV2(
-  event: any,
-): event is APIGatewayProxyEventV2 {
-  return event.version === "2.0";
-}
-
-export function isAPIGatewayProxyEvent(
-  event: any,
-): event is APIGatewayProxyEvent {
-  return event.version === undefined && !isCloudFrontRequestEvent(event);
-}
-
-export function isCloudFrontRequestEvent(
-  event: any,
-): event is CloudFrontRequestEvent {
-  return event.Records !== undefined;
-}
-
-export function convertFrom(
-  event: APIGatewayProxyEventV2 | APIGatewayProxyEvent | CloudFrontRequestEvent,
-): InternalEvent {
-  let internalEvent: InternalEvent;
-  if (isCloudFrontRequestEvent(event)) {
-    internalEvent = convertFromCloudFrontRequestEvent(event);
-  } else if (isAPIGatewayProxyEventV2(event)) {
-    internalEvent = convertFromAPIGatewayProxyEventV2(event);
-  } else if (isAPIGatewayProxyEvent(event)) {
-    internalEvent = convertFromAPIGatewayProxyEvent(event);
-  } else throw new Error("Unsupported event type");
-
-  return internalEvent;
-}
-
-export function convertTo(
-  result: InternalResult,
-): APIGatewayProxyResultV2 | APIGatewayProxyResult | CloudFrontRequestResult {
-  if (result.type === "v2") {
-    return convertToApiGatewayProxyResultV2(result);
-  } else if (result.type === "v1") {
-    return convertToApiGatewayProxyResult(result);
-  } else if (result.type === "cf") {
-    return convertToCloudFrontRequestResult(result);
-  }
-  throw new Error("Unsupported event type");
-}
-
-function removeUndefinedFromQuery(
-  query: Record<string, string | string[] | undefined>,
-) {
-  const newQuery: Record<string, string | string[]> = {};
-  for (const [key, value] of Object.entries(query)) {
-    if (value !== undefined) {
-      newQuery[key] = value;
-    }
-  }
-  return newQuery;
-}
-function convertFromAPIGatewayProxyEvent(
-  event: APIGatewayProxyEvent,
-): InternalEvent {
-  const { path, body, httpMethod, requestContext, isBase64Encoded } = event;
-  return {
-    type: "v1",
-    method: httpMethod,
-    rawPath: path,
-    url: path + normalizeAPIGatewayProxyEventQueryParams(event),
-    body: Buffer.from(body ?? "", isBase64Encoded ? "base64" : "utf8"),
-    headers: normalizeAPIGatewayProxyEventHeaders(event),
-    remoteAddress: requestContext.identity.sourceIp,
-    query: removeUndefinedFromQuery(
-      event.multiValueQueryStringParameters ?? {},
-    ),
-    cookies:
-      event.multiValueHeaders?.cookie?.reduce((acc, cur) => {
-        const [key, value] = cur.split("=");
-        return { ...acc, [key]: value };
-      }, {}) ?? {},
-  };
-}
-
-function convertFromAPIGatewayProxyEventV2(
-  event: APIGatewayProxyEventV2,
-): InternalEvent {
-  const { rawPath, rawQueryString, requestContext } = event;
-  return {
-    type: "v2",
-    method: requestContext.http.method,
-    rawPath,
-    url: rawPath + (rawQueryString ? `?${rawQueryString}` : ""),
-    body: normalizeAPIGatewayProxyEventV2Body(event),
-    headers: normalizeAPIGatewayProxyEventV2Headers(event),
-    remoteAddress: requestContext.http.sourceIp,
-    query: removeUndefinedFromQuery(event.queryStringParameters ?? {}),
-    cookies:
-      event.cookies?.reduce((acc, cur) => {
-        const [key, value] = cur.split("=");
-        return { ...acc, [key]: value };
-      }, {}) ?? {},
-  };
-}
-
-function convertFromCloudFrontRequestEvent(
-  event: CloudFrontRequestEvent,
-): InternalEvent {
-  const { method, uri, querystring, body, headers, clientIp } =
-    event.Records[0].cf.request;
-  return {
-    type: "cf",
-    method,
-    rawPath: uri,
-    url: uri + (querystring ? `?${querystring}` : ""),
-    body: Buffer.from(
-      body?.data ?? "",
-      body?.encoding === "base64" ? "base64" : "utf8",
-    ),
-    headers: normalizeCloudFrontRequestEventHeaders(headers),
-    remoteAddress: clientIp,
-    query: querystring.split("&").reduce(
-      (acc, cur) => ({
-        ...acc,
-        [cur.split("=")[0]]: cur.split("=")[1],
-      }),
-      {},
-    ),
-    cookies:
-      headers.cookie?.reduce((acc, cur) => {
-        const { key, value } = cur;
-        return { ...acc, [key ?? ""]: value };
-      }, {}) ?? {},
-  };
-}
-
-function convertToApiGatewayProxyResult(
-  result: InternalResult,
-): APIGatewayProxyResult {
-  const headers: Record<string, string> = {};
-  const multiValueHeaders: Record<string, string[]> = {};
-  Object.entries(result.headers).forEach(([key, value]) => {
-    if (Array.isArray(value)) {
-      multiValueHeaders[key] = value;
-    } else {
-      if (value === null) {
-        headers[key] = "";
-        return;
-      }
-      headers[key] = value;
-    }
-  });
-
-  const response: APIGatewayProxyResult = {
-    statusCode: result.statusCode,
-    headers,
-    body: result.body,
-    isBase64Encoded: result.isBase64Encoded,
-    multiValueHeaders,
-  };
-  debug(response);
-  return response;
-}
-
-function convertToApiGatewayProxyResultV2(
-  result: InternalResult,
-): APIGatewayProxyResultV2 {
-  const headers: Record<string, string> = {};
-  Object.entries(result.headers)
-    .filter(([key]) => key.toLowerCase() !== "set-cookie")
-    .forEach(([key, value]) => {
-      if (value === null) {
-        headers[key] = "";
-        return;
-      }
-      headers[key] = Array.isArray(value) ? value.join(", ") : value.toString();
-    });
-
-  const response: APIGatewayProxyResultV2 = {
-    statusCode: result.statusCode,
-    headers,
-    cookies: parseCookies(result.headers["set-cookie"]),
-    body: result.body,
-    isBase64Encoded: result.isBase64Encoded,
-  };
-  debug(response);
-  return response;
-}
-
-function convertToCloudFrontRequestResult(
-  result: InternalResult,
-): CloudFrontRequestResult {
-  const headers: CloudFrontHeaders = {};
-  Object.entries(result.headers)
-    .filter(([key]) => key.toLowerCase() !== "content-length")
-    .forEach(([key, value]) => {
-      headers[key] = [
-        ...(headers[key] || []),
-        ...(Array.isArray(value)
-          ? value.map((v) => ({ key, value: v }))
-          : [{ key, value: value.toString() }]),
-      ];
-    });
-
-  const response: CloudFrontRequestResult = {
-    status: result.statusCode.toString(),
-    statusDescription: "OK",
-    headers,
-    bodyEncoding: result.isBase64Encoded ? "base64" : "text",
-    body: result.body,
-  };
-  debug(response);
-  return response;
-}
-
-function normalizeAPIGatewayProxyEventV2Headers(
-  event: APIGatewayProxyEventV2,
-): Record<string, string> {
-  const { headers: rawHeaders, cookies } = event;
-
-  const headers: Record<string, string> = {};
-
-  if (Array.isArray(cookies)) {
-    headers["cookie"] = cookies.join("; ");
-  }
-
-  for (const [key, value] of Object.entries(rawHeaders || {})) {
-    headers[key.toLowerCase()] = value!;
-  }
-
-  return headers;
-}
-
-function normalizeAPIGatewayProxyEventV2Body(
-  event: APIGatewayProxyEventV2,
-): Buffer {
-  const { body, isBase64Encoded } = event;
-  if (Buffer.isBuffer(body)) {
-    return body;
-  } else if (typeof body === "string") {
-    return Buffer.from(body, isBase64Encoded ? "base64" : "utf8");
-  } else if (typeof body === "object") {
-    return Buffer.from(JSON.stringify(body));
-  }
-  return Buffer.from("", "utf8");
-}
-
-function normalizeAPIGatewayProxyEventQueryParams(
-  event: APIGatewayProxyEvent,
-): string {
-  // Note that the same query string values are returned in both
-  // "multiValueQueryStringParameters" and "queryStringParameters".
-  // We only need to use one of them.
-  // For example:
-  //   "?name=foo" appears in the event object as
-  //   {
-  //     ...
-  //     queryStringParameters: { name: 'foo' },
-  //     multiValueQueryStringParameters: { name: [ 'foo' ] },
-  //     ...
-  //   }
-  const params = new URLSearchParams();
-  for (const [key, value] of Object.entries(
-    event.multiValueQueryStringParameters || {},
-  )) {
-    if (value !== undefined) {
-      for (const v of value) {
-        params.append(key, v);
-      }
-    }
-  }
-  const value = params.toString();
-  return value ? `?${value}` : "";
-}
-
-function normalizeAPIGatewayProxyEventHeaders(
-  event: APIGatewayProxyEvent,
-): Record<string, string> {
-  event.multiValueHeaders;
-  const headers: Record<string, string> = {};
-
-  for (const [key, values] of Object.entries(event.multiValueHeaders || {})) {
-    if (values) {
-      headers[key.toLowerCase()] = values.join(",");
-    }
-  }
-  for (const [key, value] of Object.entries(event.headers || {})) {
-    if (value) {
-      headers[key.toLowerCase()] = value;
-    }
-  }
-  return headers;
-}
-
-function normalizeCloudFrontRequestEventHeaders(
-  rawHeaders: CloudFrontHeaders,
-): Record<string, string> {
-  const headers: Record<string, string> = {};
-
-  for (const [key, values] of Object.entries(rawHeaders)) {
-    for (const { value } of values) {
-      if (value) {
-        headers[key.toLowerCase()] = value;
-      }
-    }
-  }
-
-  return headers;
-}
diff --git a/packages/open-next/src/adapters/http/index.ts b/packages/open-next/src/adapters/http/index.ts
deleted file mode 100644
index 82e9e9411..000000000
--- a/packages/open-next/src/adapters/http/index.ts
+++ /dev/null
@@ -1,3 +0,0 @@
-export * from "./request.js";
-export * from "./response.js";
-export * from "./responseStreaming.js";
diff --git a/packages/open-next/src/adapters/http/response.ts b/packages/open-next/src/adapters/http/response.ts
deleted file mode 100644
index 9731f55d5..000000000
--- a/packages/open-next/src/adapters/http/response.ts
+++ /dev/null
@@ -1,150 +0,0 @@
-// Copied and modified from serverless-http by Doug Moscrop
-// https://github.com/dougmoscrop/serverless-http/blob/master/lib/response.js
-// Licensed under the MIT License
-
-import http from "node:http";
-import { Socket } from "node:net";
-
-import {
-  convertHeader,
-  getString,
-  headerEnd,
-  NO_OP,
-  parseHeaders,
-} from "./util.js";
-
-const BODY = Symbol();
-const HEADERS = Symbol();
-
-function addData(stream: ServerlessResponse, data: Uint8Array | string) {
-  if (
-    Buffer.isBuffer(data) ||
-    ArrayBuffer.isView(data) ||
-    typeof data === "string"
-  ) {
-    stream[BODY].push(Buffer.from(data));
-  } else {
-    throw new Error(`response.addData() of unexpected type: ${typeof data}`);
-  }
-}
-
-export interface ServerlessResponseProps {
-  method: string;
-  headers: Record<string, string | string[] | undefined>;
-}
-
-export class ServerlessResponse extends http.ServerResponse {
-  [BODY]: Buffer[];
-  [HEADERS]: Record<string, string>;
-  private _wroteHeader = false;
-  private _header = "";
-  private _initialHeaders: Record<string, string> = {};
-
-  constructor({ method, headers }: ServerlessResponseProps) {
-    super({ method, headers } as any);
-
-    this[BODY] = [];
-    this[HEADERS] = parseHeaders(headers) || {};
-    this._initialHeaders = this[HEADERS];
-
-    this.useChunkedEncodingByDefault = false;
-    this.chunkedEncoding = false;
-    this._header = "";
-
-    const socket: Partial<Socket> & { _writableState: any } = {
-      _writableState: {},
-      writable: true,
-      on: NO_OP,
-      removeListener: NO_OP,
-      destroy: NO_OP,
-      cork: NO_OP,
-      uncork: NO_OP,
-      write: (
-        data: Uint8Array | string,
-        encoding?: string | null | (() => void),
-        cb?: () => void,
-      ) => {
-        if (typeof encoding === "function") {
-          cb = encoding;
-          encoding = null;
-        }
-
-        if (this._header === "" || this._wroteHeader) {
-          addData(this, data);
-        } else {
-          const string = getString(data);
-          const index = string.indexOf(headerEnd);
-
-          if (index !== -1) {
-            const remainder = string.slice(index + headerEnd.length);
-
-            if (remainder) {
-              addData(this, remainder);
-            }
-
-            this._wroteHeader = true;
-          }
-        }
-
-        if (typeof cb === "function") {
-          cb();
-        }
-        return true;
-      },
-    };
-
-    this.assignSocket(socket as Socket);
-
-    this.once("finish", () => {
-      this.emit("close");
-    });
-  }
-
-  static body(res: ServerlessResponse) {
-    return Buffer.concat(res[BODY]);
-  }
-
-  static headers(res: ServerlessResponse) {
-    const headers =
-      typeof res.getHeaders === "function" ? res.getHeaders() : res[HEADERS];
-
-    return {
-      ...parseHeaders(headers),
-      ...res[HEADERS],
-      ...res._initialHeaders,
-    };
-  }
-
-  get headers() {
-    return this[HEADERS];
-  }
-
-  setHeader(key: string, value: string | number | string[]): this {
-    if (this._wroteHeader) {
-      this[HEADERS][key] = convertHeader(value);
-    } else {
-      super.setHeader(key, value);
-    }
-    return this;
-  }
-
-  writeHead(
-    statusCode: number,
-    reason?: string | any | any[],
-    obj?: any | any[],
-  ) {
-    const headers = typeof reason === "string" ? obj : reason;
-
-    for (const name in headers) {
-      this.setHeader(name, headers[name]);
-
-      if (!this._wroteHeader) {
-        // we only need to initiate super.headers once
-        // writeHead will add the other headers itself
-        break;
-      }
-    }
-
-    return super.writeHead(statusCode, reason, obj);
-  }
-}
diff --git a/packages/open-next/src/adapters/http/responseStreaming.ts b/packages/open-next/src/adapters/http/responseStreaming.ts
deleted file mode 100644
index 233b27587..000000000
--- a/packages/open-next/src/adapters/http/responseStreaming.ts
+++ /dev/null
@@ -1,268 +0,0 @@
-import http from "node:http";
-import { Socket } from "node:net";
-import zlib from "node:zlib";
-
-import { debug, error } from "../logger.js";
-import type { ResponseStream } from "../types/aws-lambda.js";
-import { parseCookies } from "../util.js";
-import { convertHeader, getString, NO_OP, parseHeaders } from "./util.js";
-
-const HEADERS = Symbol();
-
-export interface StreamingServerResponseProps {
-  method?: string;
-  headers?: Record<string, string | string[] | undefined>;
-  responseStream: ResponseStream;
-  fixHeaders: (headers: Record<string, string>) => void;
-  onEnd: (headers: Record<string, string>) => Promise<void>;
-}
-export class StreamingServerResponse extends http.ServerResponse {
-  [HEADERS]: Record<string, string> = {};
-  responseStream: ResponseStream;
-  fixHeaders: (headers: Record<string, string>) => void;
-  onEnd: (headers: Record<string, string>) => Promise<void>;
-  private _wroteHeader = false;
-  private _hasWritten = false;
-  private _initialHeaders: Record<string, string> = {};
-  private _cookies: string[] = [];
-  private _compressed = false;
-
-  constructor({
-    method,
-    headers,
-    responseStream,
-    fixHeaders,
-    onEnd,
-  }: StreamingServerResponseProps) {
-    super({ method } as any);
-    if (headers && headers["set-cookie"]) {
-      this._cookies = parseCookies(headers["set-cookie"]) as string[];
-      delete headers["set-cookie"];
-    }
-    this[HEADERS] = parseHeaders(headers) || {};
-    this._initialHeaders = { ...this[HEADERS] };
-
-    this.fixHeaders = fixHeaders;
-    this.onEnd = onEnd;
-    this.responseStream = responseStream;
-
-    this.useChunkedEncodingByDefault = false;
-    this.chunkedEncoding = false;
-
-    this.responseStream.cork();
-
-    const socket: Partial<Socket> & { _writableState: any } = {
-      _writableState: {},
-      writable: true,
-      on: NO_OP,
-      removeListener: NO_OP,
-      destroy: NO_OP,
-      cork: NO_OP,
-      uncork: NO_OP,
-      write: (
-        data: Uint8Array | string,
-        encoding?: string | null | (() => void),
-        cb?: () => void,
-      ) => {
-        if (typeof encoding === "function") {
-          cb = encoding;
-          encoding = undefined;
-        }
-        const d = getString(data);
-        const isSse = d.endsWith("\n\n");
-        this.internalWrite(data, isSse, cb);
-
-        return !this.responseStream.writableNeedDrain;
-      },
-    };
-
-    this.assignSocket(socket as Socket);
-
-    this.responseStream.on("close", this.cancel.bind(this));
-    this.responseStream.on("error", this.cancel.bind(this));
-
-    this.on("close", this.cancel.bind(this));
-    this.on("error", this.cancel.bind(this));
-    this.once("finish", () => {
-      this.emit("close");
-    });
-  }
-
-  get headers() {
-    return this[HEADERS];
-  }
-
-  setHeader(key: string, value: string | number | string[]): this {
-    key = key.toLowerCase();
-    // There can be multiple set-cookie response headers
-    // They need to be returned as a special "cookies" array, eg:
-    // {statusCode: xxx, cookies: ['Cookie=Yum'], ...}
-    if (key === "set-cookie") {
-      this._cookies.push(convertHeader(value));
-    } else {
-      this[HEADERS][key] = convertHeader(value);
-    }
-    return this;
-  }
-
-  removeHeader(key: string): this {
-    key = key.toLowerCase();
-    if (key === "set-cookie") {
-      this._cookies.length = 0;
-    } else {
-      delete this[HEADERS][key];
-    }
-    return this;
-  }
-
-  writeHead(
-    statusCode: number,
-    _statusMessage?:
-      | string
-      | http.OutgoingHttpHeaders
-      | http.OutgoingHttpHeader[],
-    _headers?: http.OutgoingHttpHeaders | http.OutgoingHttpHeader[],
-  ): this {
-    const headers =
-      typeof _statusMessage === "string" ? _headers : _statusMessage;
-    const statusMessage =
-      typeof _statusMessage === "string" ? _statusMessage : undefined;
-    if (this._wroteHeader) {
-      return this;
-    }
-    try {
-      debug("writeHead", statusCode, statusMessage, headers);
-      const parsedHeaders = parseHeaders(headers);
-      this[HEADERS] = {
-        ...this[HEADERS],
-        ...parsedHeaders,
-      };
-
-      this.fixHeaders(this[HEADERS]);
-      this[HEADERS] = {
-        ...this[HEADERS],
-        ...this._initialHeaders,
-      };
-
-      this._compressed = this[HEADERS]["accept-encoding"]?.includes("br");
-      if (this._compressed) {
-        this[HEADERS]["content-encoding"] = "br";
-      }
-      delete this[HEADERS]["accept-encoding"];
-
-      debug("writeHead", this[HEADERS]);
-
-      this._wroteHeader = true;
-      // FIXME: This is extracted from the docker lambda node 18 runtime
-      // https://gist.github.com/conico974/13afd708af20711b97df439b910ceb53#file-index-mjs-L921-L932
-      // We replace their write with ours which are inside a setImmediate
-      // This way it seems to work all the time
-      // I think we can't ship this code as it is, it could break at anytime if they decide to change the runtime and they already did it in the past
-      this.responseStream.setContentType(
-        "application/vnd.awslambda.http-integration-response",
-      );
-      const prelude = JSON.stringify({
-        statusCode: statusCode as number,
-        cookies: this._cookies,
-        headers: this[HEADERS],
-      });
-
-      // Try to flush the buffer to the client to invoke
-      // the streaming. This does not work 100% of the time.
-      setImmediate(() => {
-        this.responseStream.write("\n\n");
-        this.responseStream.uncork();
-      });
-      setImmediate(() => {
-        this.responseStream.write(prelude);
-      });
-
-      setImmediate(() => {
-        this.responseStream.write(new Uint8Array(8));
-
-        // After headers are written, compress all writes
-        // using Brotli
-        if (this._compressed) {
-          const br = zlib.createBrotliCompress({
-            flush: zlib.constants.BROTLI_OPERATION_FLUSH,
-          });
-          br.setMaxListeners(100);
-          br.pipe(this.responseStream);
-          this.responseStream = br as unknown as ResponseStream;
-        }
-      });
-
-      debug("writeHead", this[HEADERS]);
-    } catch (e) {
-      this.responseStream.end();
-      error(e);
-    }
-
-    return this;
-  }
-
-  end(
-    _chunk?: Uint8Array | string | (() => void),
-    _encoding?: BufferEncoding | (() => void),
-    _cb?: (() => void) | undefined,
-  ): this {
-    const chunk = typeof _chunk === "function" ? undefined : _chunk;
-    const cb = typeof _cb === "function" ? _cb : undefined;
-
-    if (!this._wroteHeader) {
-      // When next directly returns with end, the writeHead is not called,
-      // so we need to call it here
-      this.writeHead(this.statusCode ?? 200);
-    }
-
-    if (!this._hasWritten && !chunk) {
-      // We need to send data here if there is none, otherwise the stream will not end at all
-      this.internalWrite(new Uint8Array(8), false, cb);
-    }
-
-    const _end = () => {
-      setImmediate(() => {
-        this.responseStream.end(_chunk, async () => {
-          if (this._compressed) {
-            (this.responseStream as unknown as zlib.BrotliCompress).flush(
-              zlib.constants.BROTLI_OPERATION_FINISH,
-            );
-          }
-          await this.onEnd(this[HEADERS]);
-          cb?.();
-        });
-      });
-    };
-
-    if (this.responseStream.writableNeedDrain) {
-      this.responseStream.once("drain", _end);
-    } else {
-      _end();
-    }
-    return this;
-  }
-
-  private internalWrite(chunk: any, isSse: boolean = false, cb?: () => void) {
-    this._hasWritten = true;
-    setImmediate(() => {
-      this.responseStream.write(chunk, cb);
-
-      // SSE need to flush to send to client ASAP
-      if (isSse) {
-        setImmediate(() => {
-          this.responseStream.write("\n\n");
-          this.responseStream.uncork();
-        });
-      }
-    });
-  }
-
-  cancel(error?: Error) {
-    this.responseStream.off("close", this.cancel.bind(this));
-    this.responseStream.off("error", this.cancel.bind(this));
-
-    if (error) {
-      this.responseStream.destroy(error);
-    }
-  }
-}
diff --git a/packages/open-next/src/adapters/http/util.ts b/packages/open-next/src/adapters/http/util.ts
deleted file mode 100644
index 132f6798b..000000000
--- a/packages/open-next/src/adapters/http/util.ts
+++ /dev/null
@@ -1,50 +0,0 @@
-import http from "node:http";
-
-export function getString(data: any) {
-  // Note: use `ArrayBuffer.isView()` to check for Uint8Array. Using
-  //       `instanceof Uint8Array` returns false in some cases. For example,
-  //       when the buffer is created in middleware and passed to NextServer.
-  if (Buffer.isBuffer(data)) {
-    return data.toString("utf8");
-  } else if (ArrayBuffer.isView(data)) {
-    //@ts-ignore
-    return Buffer.from(data).toString("utf8");
-  } else if (typeof data === "string") {
-    return data;
-  } else {
-    throw new Error(`response.getString() of unexpected type: ${typeof data}`);
-  }
-}
-
-export const headerEnd = "\r\n\r\n";
-
-export const NO_OP: (...args: any[]) => any = () => void 0;
-
-export const parseHeaders = (
-  headers?: http.OutgoingHttpHeader[] | http.OutgoingHttpHeaders,
-) => {
-  const result: Record<string, string> = {};
-  if (!headers) {
-    return result;
-  }
-
-  for (const [key, value] of Object.entries(headers)) {
-    if (value === undefined) {
-      continue;
-    } else {
-      result[key] = convertHeader(value);
-    }
-  }
-
-  return result;
-};
-
-export const convertHeader = (header: http.OutgoingHttpHeader) => {
-  if (typeof header === "string") {
-    return header;
-  } else if (Array.isArray(header)) {
-    return header.join(",");
-  } else {
-    return String(header);
-  }
-};
diff --git a/packages/open-next/src/adapters/image-optimization-adapter.ts b/packages/open-next/src/adapters/image-optimization-adapter.ts
index f5fbb26bc..d8bb958f6 100644
--- a/packages/open-next/src/adapters/image-optimization-adapter.ts
+++ b/packages/open-next/src/adapters/image-optimization-adapter.ts
@@ -1,16 +1,15 @@
-import { IncomingMessage, ServerResponse } from "node:http";
+import {
+  IncomingMessage,
+  OutgoingHttpHeaders,
+  ServerResponse,
+} from "node:http";
 import https from "node:https";
 import path from "node:path";
 import { Writable } from "node:stream";
 
 import { GetObjectCommand, S3Client } from "@aws-sdk/client-s3";
-import type {
-  APIGatewayProxyEvent,
-  APIGatewayProxyEventHeaders,
-  APIGatewayProxyEventQueryStringParameters,
-  APIGatewayProxyEventV2,
-  APIGatewayProxyResultV2,
-} from "aws-lambda";
+import type { APIGatewayProxyEventHeaders } from "aws-lambda";
+import { loadConfig } from "config/util.js";
 // @ts-ignore
 import { defaultConfig } from "next/dist/server/config-shared";
 import {
@@ -20,8 +19,9 @@ import {
 } from "next/dist/server/image-optimizer";
 // @ts-ignore
 import type { NextUrlWithParsedQuery } from "next/dist/server/request-meta";
+import { InternalEvent, InternalResult } from "types/open-next.js";
 
-import { loadConfig } from "./config/util.js";
+import { createGenericHandler } from "../core/createGenericHandler.js";
 import { awsLogger, debug, error } from "./logger.js";
 import { setNodeEnv } from "./util.js";
 
@@ -50,15 +50,20 @@ debug("Init config", {
 // Handler //
 /////////////
 
-export async function handler(
-  event: APIGatewayProxyEventV2 | APIGatewayProxyEvent,
-): Promise<APIGatewayProxyResultV2> {
+export const handler = await createGenericHandler({
+  handler: defaultHandler,
+  type: "imageOptimization",
+});
+
+export async function defaultHandler(
+  event: InternalEvent,
+): Promise<InternalResult> {
   // Images are handled via header and query param information.
   debug("handler event", event);
-  const { headers: rawHeaders, queryStringParameters: queryString } = event;
+  const { headers, query: queryString } = event;
 
   try {
-    const headers = normalizeHeaderKeysToLowercase(rawHeaders);
+    // const headers = normalizeHeaderKeysToLowercase(rawHeaders);
     ensureBucketExists();
     const imageParams = validateImageParams(
       headers,
@@ -76,13 +81,13 @@ export async function handler(
 // Helper functions //
 //////////////////////
 
-function normalizeHeaderKeysToLowercase(headers: APIGatewayProxyEventHeaders) {
-  // Make header keys lowercase to ensure integrity
-  return Object.entries(headers).reduce(
-    (acc, [key, value]) => ({ ...acc, [key.toLowerCase()]: value }),
-    {} as APIGatewayProxyEventHeaders,
-  );
-}
+// function normalizeHeaderKeysToLowercase(headers: APIGatewayProxyEventHeaders) {
+//   // Make header keys lowercase to ensure integrity
+//   return Object.entries(headers).reduce(
+//     (acc, [key, value]) => ({ ...acc, [key.toLowerCase()]: value }),
+//     {} as APIGatewayProxyEventHeaders,
+//   );
+// }
 
 function ensureBucketExists() {
   if (!BUCKET_NAME) {
@@ -91,15 +96,15 @@ function ensureBucketExists() {
 }
 
 function validateImageParams(
-  headers: APIGatewayProxyEventHeaders,
-  queryString?: APIGatewayProxyEventQueryStringParameters,
+  headers: OutgoingHttpHeaders,
+  query?: InternalEvent["query"],
 ) {
   // Next.js checks if external image URL matches the
   // `images.remotePatterns`
   const imageParams = ImageOptimizerCache.validateParams(
     // @ts-ignore
     { headers },
-    queryString,
+    query,
     nextConfig,
     false,
   );
@@ -127,8 +132,9 @@ async function optimizeImage(
   return result;
 }
 
-function buildSuccessResponse(result: any) {
+function buildSuccessResponse(result: any): InternalResult {
   return {
+    type: "core",
     statusCode: 200,
     body: result.buffer.toString("base64"),
     isBase64Encoded: true,
@@ -140,9 +146,11 @@ function buildSuccessResponse(result: any) {
   };
 }
 
-function buildFailureResponse(e: any) {
+function buildFailureResponse(e: any): InternalResult {
   debug(e);
   return {
+    type: "core",
+    isBase64Encoded: false,
     statusCode: 500,
     headers: {
       Vary: "Accept",
@@ -154,6 +162,31 @@ function buildFailureResponse(e: any) {
   };
 }
 
+const resolveLoader = () => {
+  const openNextParams = globalThis.openNextConfig.imageOptimization;
+  if (typeof openNextParams?.loader === "function") {
+    return openNextParams.loader();
+  } else {
+    return Promise.resolve(async (key: string) => {
+      const keyPrefix = BUCKET_KEY_PREFIX?.replace(/^\/|\/$/g, "");
+      const response = await s3Client.send(
+        new GetObjectCommand({
+          Bucket: BUCKET_NAME,
+          Key: keyPrefix
+            ? keyPrefix + "/" + key.replace(/^\//, "")
+            : key.replace(/^\//, ""),
+        }),
+      );
+      return {
+        body: response.Body,
+        contentType: response.ContentType,
+        cacheControl: response.CacheControl,
+      };
+    });
+  }
+};
+const loader = await resolveLoader();
+
 async function downloadHandler(
   _req: IncomingMessage,
   res: ServerResponse,
@@ -186,30 +219,23 @@ async function downloadHandler(
     else {
       // Download image from S3
       // note: S3 expects keys without leading `/`
-      const keyPrefix = BUCKET_KEY_PREFIX?.replace(/^\/|\/$/g, "");
-      const response = await s3Client.send(
-        new GetObjectCommand({
-          Bucket: BUCKET_NAME,
-          Key: keyPrefix
-            ? keyPrefix + "/" + url.href.replace(/^\//, "")
-            : url.href.replace(/^\//, ""),
-        }),
-      );
 
-      if (!response.Body) {
+      const response = await loader(url.href);
+
+      if (!response.body) {
         throw new Error("Empty response body from the S3 request.");
       }
 
       // @ts-ignore
-      pipeRes(response.Body, res);
+      pipeRes(response.body, res);
 
       // Respect the bucket file's content-type and cache-control
       // imageOptimizer will use this to set the results.maxAge
-      if (response.ContentType) {
-        res.setHeader("Content-Type", response.ContentType);
+      if (response.contentType) {
+        res.setHeader("Content-Type", response.contentType);
       }
-      if (response.CacheControl) {
-        res.setHeader("Cache-Control", response.CacheControl);
+      if (response.cacheControl) {
+        res.setHeader("Cache-Control", response.cacheControl);
       }
     }
   } catch (e: any) {
diff --git a/packages/open-next/src/adapters/middleware.ts b/packages/open-next/src/adapters/middleware.ts
new file mode 100644
index 000000000..a5c59dd62
--- /dev/null
+++ b/packages/open-next/src/adapters/middleware.ts
@@ -0,0 +1,29 @@
+import { InternalEvent } from "types/open-next";
+
+import { createGenericHandler } from "../core/createGenericHandler";
+import routingHandler from "../core/routingHandler";
+
+const defaultHandler = async (internalEvent: InternalEvent) => {
+  // TODO: We need to handle splitted function here
+  // We should probably create an host resolver to redirect correctly
+  const result = await routingHandler(internalEvent);
+  if ("internalEvent" in result) {
+    return {
+      type: "middleware",
+      internalEvent: result.internalEvent,
+      headers: result.headers,
+      isExternalRewrite: result.isExternalRewrite,
+    };
+  } else {
+    return result;
+  }
+};
+
+export const handler = await createGenericHandler({
+  handler: defaultHandler,
+  type: "middleware",
+});
+
+export default {
+  fetch: handler,
+};
diff --git a/packages/open-next/src/adapters/plugins/13.5/serverHandler.ts b/packages/open-next/src/adapters/plugins/13.5/serverHandler.ts
deleted file mode 100644
index dc7f98647..000000000
--- a/packages/open-next/src/adapters/plugins/13.5/serverHandler.ts
+++ /dev/null
@@ -1,25 +0,0 @@
-/*eslint-disable simple-import-sort/imports */
-import type { Options, PluginHandler } from "../../types/next-types.js";
-import type { IncomingMessage } from "../../http/request.js";
-import type { ServerlessResponse } from "../../http/response.js";
-//#override imports
-//@ts-ignore
-import { requestHandler } from "./util.js";
-//@ts-ignore
-import { proxyRequest } from "./routing/util.js";
-//#endOverride
-
-//#override handler
-export const handler: PluginHandler = async (
-  req: IncomingMessage,
-  res: ServerlessResponse,
-  options: Options,
-) => {
-  if (options.isExternalRewrite) {
-    return proxyRequest(req, res);
-  } else {
-    // Next Server
-    return requestHandler(req, res);
-  }
-};
-//#endOverride
diff --git a/packages/open-next/src/adapters/plugins/13.5/util.ts b/packages/open-next/src/adapters/plugins/13.5/util.ts
deleted file mode 100644
index 4bf53b923..000000000
--- a/packages/open-next/src/adapters/plugins/13.5/util.ts
+++ /dev/null
@@ -1,5 +0,0 @@
-import { debug } from "../../logger.js";
-
-//#override requireHooks
-debug("No need to override require hooks with next 13.4.20+");
-//#endOverride
diff --git a/packages/open-next/src/adapters/plugins/lambdaHandler.ts b/packages/open-next/src/adapters/plugins/lambdaHandler.ts
deleted file mode 100644
index 7d7a614e9..000000000
--- a/packages/open-next/src/adapters/plugins/lambdaHandler.ts
+++ /dev/null
@@ -1,139 +0,0 @@
-import {
-  APIGatewayProxyEvent,
-  APIGatewayProxyEventV2,
-  CloudFrontRequestEvent,
-} from "aws-lambda";
-
-import { BuildId, PublicAssets } from "../config";
-import { convertFrom, convertTo, InternalEvent } from "../event-mapper";
-import { type IncomingMessage, ServerlessResponse } from "../http";
-import { debug, error } from "../logger";
-import { CreateResponse } from "../types/plugin";
-import { generateUniqueId } from "../util";
-import { WarmerEvent, WarmerResponse } from "../warmer-function";
-//#override imports
-import {
-  postProcessResponse,
-  processInternalEvent,
-} from "./routing/default.js";
-//#endOverride
-import { handler as serverHandler } from "./serverHandler";
-
-const serverId = `server-${generateUniqueId()}`;
-
-//#override lambdaHandler
-export async function lambdaHandler(
-  event:
-    | APIGatewayProxyEventV2
-    | CloudFrontRequestEvent
-    | APIGatewayProxyEvent
-    | WarmerEvent,
-) {
-  debug("event", event);
-  // Handler warmer
-  if ("type" in event) {
-    return formatWarmerResponse(event);
-  }
-
-  // Parse Lambda event and create Next.js request
-  const internalEvent = convertFrom(event);
-
-  // WORKAROUND: Set `x-forwarded-host` header (AWS specific) — https://github.com/serverless-stack/open-next#workaround-set-x-forwarded-host-header-aws-specific
-  if (internalEvent.headers["x-forwarded-host"]) {
-    internalEvent.headers.host = internalEvent.headers["x-forwarded-host"];
-  }
-
-  // WORKAROUND: public/ static files served by the server function (AWS specific) — https://github.com/serverless-stack/open-next#workaround-public-static-files-served-by-the-server-function-aws-specific
-  // TODO: This is no longer required if each top-level file and folder in "/public"
-  //       is handled by a separate cache behavior. Leaving here for backward compatibility.
-  //       Remove this on next major release.
-  if (PublicAssets.files.includes(internalEvent.rawPath)) {
-    return internalEvent.type === "cf"
-      ? formatCloudFrontFailoverResponse(event as CloudFrontRequestEvent)
-      : formatAPIGatewayFailoverResponse();
-  }
-
-  const createServerResponse: CreateResponse<ServerlessResponse> = (
-    method,
-    headers,
-  ) => new ServerlessResponse({ method, headers });
-
-  const preprocessResult = await processInternalEvent(
-    internalEvent,
-    createServerResponse,
-  );
-  if ("type" in preprocessResult) {
-    return convertTo(preprocessResult);
-  } else {
-    const {
-      req,
-      res,
-      isExternalRewrite,
-      internalEvent: overwrittenInternalEvent,
-    } = preprocessResult;
-
-    await processRequest(req, res, overwrittenInternalEvent, isExternalRewrite);
-
-    const internalResult = await postProcessResponse({
-      internalEvent: overwrittenInternalEvent,
-      req,
-      res,
-      isExternalRewrite,
-    });
-
-    return convertTo(internalResult);
-  }
-}
-//#endOverride
-
-async function processRequest(
-  req: IncomingMessage,
-  res: ServerlessResponse,
-  internalEvent: InternalEvent,
-  isExternalRewrite?: boolean,
-) {
-  // @ts-ignore
-  // Next.js doesn't parse body if the property exists
-  // https://github.com/dougmoscrop/serverless-http/issues/227
-  delete req.body;
-
-  try {
-    // `serverHandler` is replaced at build time depending on user's
-    // nextjs version to patch Nextjs 13.4.x and future breaking changes.
-    await serverHandler(req, res, {
-      internalEvent,
-      buildId: BuildId,
-      isExternalRewrite,
-    });
-  } catch (e: any) {
-    error("NextJS request failed.", e);
-
-    res.setHeader("Content-Type", "application/json");
-    res.end(
-      JSON.stringify(
-        {
-          message: "Server failed to respond.",
-          details: e,
-        },
-        null,
-        2,
-      ),
-    );
-  }
-}
-
-function formatAPIGatewayFailoverResponse() {
-  return { statusCode: 503 };
-}
-
-function formatCloudFrontFailoverResponse(event: CloudFrontRequestEvent) {
-  return event.Records[0].cf.request;
-}
-
-function formatWarmerResponse(event: WarmerEvent) {
-  return new Promise<WarmerResponse>((resolve) => {
-    setTimeout(() => {
-      resolve({ serverId } satisfies WarmerResponse);
-    }, event.delay);
-  });
-}
diff --git a/packages/open-next/src/adapters/plugins/routing/default.replacement.ts b/packages/open-next/src/adapters/plugins/routing/default.replacement.ts
deleted file mode 100644
index 3388d1f08..000000000
--- a/packages/open-next/src/adapters/plugins/routing/default.replacement.ts
+++ /dev/null
@@ -1,157 +0,0 @@
-/* eslint-disable simple-import-sort/imports */
-import type {
-  PostProcessOptions,
-  ProcessInternalEvent,
-} from "../../types/plugin";
-import type { InternalResult } from "../../event-mapper";
-//#override imports
-
-import { debug } from "../../logger";
-import { IncomingMessage } from "../../http/request";
-import {
-  addNextConfigHeaders,
-  fixDataPage,
-  handleFallbackFalse,
-  handleRedirects,
-  handleRewrites,
-} from "../../routing/matcher";
-import {
-  addOpenNextHeader,
-  fixCacheHeaderForHtmlPages,
-  fixISRHeaders,
-  fixSWRCacheHeader,
-  revalidateIfRequired,
-} from "./util";
-import { convertRes } from "../../routing/util";
-import { handleMiddleware } from "../../routing/middleware";
-import { ServerlessResponse } from "../../http";
-import {
-  BuildId,
-  ConfigHeaders,
-  PrerenderManifest,
-  RoutesManifest,
-} from "../../config";
-
-//#endOverride
-
-//#override processInternalEvent
-export const processInternalEvent: ProcessInternalEvent = async (
-  event,
-  createResponse,
-) => {
-  const nextHeaders = addNextConfigHeaders(event, ConfigHeaders) ?? {};
-
-  let internalEvent = fixDataPage(event, BuildId);
-
-  internalEvent = handleFallbackFalse(internalEvent, PrerenderManifest);
-
-  const redirect = handleRedirects(internalEvent, RoutesManifest.redirects);
-  if (redirect) {
-    return redirect;
-  }
-
-  const middleware = await handleMiddleware(internalEvent);
-  let middlewareResponseHeaders: Record<string, string | string[]> = {};
-  if ("statusCode" in middleware) {
-    return middleware;
-  } else {
-    middlewareResponseHeaders = middleware.responseHeaders || {};
-    internalEvent = middleware;
-  }
-
-  let isExternalRewrite = middleware.externalRewrite ?? false;
-  if (!isExternalRewrite) {
-    // First rewrite to be applied
-    const beforeRewrites = handleRewrites(
-      internalEvent,
-      RoutesManifest.rewrites.beforeFiles,
-    );
-    internalEvent = beforeRewrites.internalEvent;
-    isExternalRewrite = beforeRewrites.isExternalRewrite;
-  }
-  const isStaticRoute = RoutesManifest.routes.static.some((route) =>
-    new RegExp(route.regex).test(event.rawPath),
-  );
-
-  if (!isStaticRoute && !isExternalRewrite) {
-    // Second rewrite to be applied
-    const afterRewrites = handleRewrites(
-      internalEvent,
-      RoutesManifest.rewrites.afterFiles,
-    );
-    internalEvent = afterRewrites.internalEvent;
-    isExternalRewrite = afterRewrites.isExternalRewrite;
-  }
-
-  const isDynamicRoute = RoutesManifest.routes.dynamic.some((route) =>
-    new RegExp(route.regex).test(event.rawPath),
-  );
-  if (!isDynamicRoute && !isStaticRoute && !isExternalRewrite) {
-    // Fallback rewrite to be applied
-    const fallbackRewrites = handleRewrites(
-      internalEvent,
-      RoutesManifest.rewrites.fallback,
-    );
-    internalEvent = fallbackRewrites.internalEvent;
-    isExternalRewrite = fallbackRewrites.isExternalRewrite;
-  }
-
-  const reqProps = {
-    method: internalEvent.method,
-    url: internalEvent.url,
-    //WORKAROUND: We pass this header to the serverless function to mimic a prefetch request which will not trigger revalidation since we handle revalidation differently
-    // There is 3 way we can handle revalidation:
-    // 1. We could just let the revalidation go as normal, but due to race condtions the revalidation will be unreliable
-    // 2. We could alter the lastModified time of our cache to make next believe that the cache is fresh, but this could cause issues with stale data since the cdn will cache the stale data as if it was fresh
-    // 3. OUR CHOICE: We could pass a purpose prefetch header to the serverless function to make next believe that the request is a prefetch request and not trigger revalidation (This could potentially break in the future if next changes the behavior of prefetch requests)
-    headers: { ...internalEvent.headers, purpose: "prefetch" },
-    body: internalEvent.body,
-    remoteAddress: internalEvent.remoteAddress,
-  };
-  debug("IncomingMessage constructor props", reqProps);
-  const req = new IncomingMessage(reqProps);
-  const res = createResponse(reqProps.method, {
-    ...nextHeaders,
-    ...middlewareResponseHeaders,
-  });
-
-  return { internalEvent: internalEvent, req, res, isExternalRewrite };
-};
-//#endOverride
-
-//#override postProcessResponse
-export async function postProcessResponse({
-  internalEvent,
-  req,
-  res,
-  isExternalRewrite,
-}: PostProcessOptions): Promise<InternalResult> {
-  const { statusCode, headers, isBase64Encoded, body } = convertRes(
-    res as ServerlessResponse,
-  );
-
-  debug("ServerResponse data", { statusCode, headers, isBase64Encoded, body });
-
-  if (!isExternalRewrite) {
-    fixCacheHeaderForHtmlPages(internalEvent.rawPath, headers);
-    fixSWRCacheHeader(headers);
-    addOpenNextHeader(headers);
-    fixISRHeaders(headers);
-
-    await revalidateIfRequired(
-      internalEvent.headers.host,
-      internalEvent.rawPath,
-      headers,
-      req,
-    );
-  }
-
-  return {
-    type: internalEvent.type,
-    statusCode,
-    headers,
-    body,
-    isBase64Encoded,
-  };
-}
-//#endOverride
diff --git a/packages/open-next/src/adapters/plugins/routing/default.ts b/packages/open-next/src/adapters/plugins/routing/default.ts
deleted file mode 100644
index 5f2694dad..000000000
--- a/packages/open-next/src/adapters/plugins/routing/default.ts
+++ /dev/null
@@ -1,81 +0,0 @@
-/* eslint-disable simple-import-sort/imports */
-import type {
-  CreateResponse,
-  PostProcessOptions,
-  ProcessInternalEventResult,
-} from "../../types/plugin";
-import type { InternalEvent, InternalResult } from "../../event-mapper";
-//#override imports
-import { debug } from "../../logger";
-import { IncomingMessage } from "../../http/request";
-import {
-  addOpenNextHeader,
-  fixCacheHeaderForHtmlPages,
-  fixISRHeaders,
-  fixSWRCacheHeader,
-  revalidateIfRequired,
-} from "./util";
-import { convertRes } from "../../routing/util";
-import { ServerlessResponse } from "../../http";
-import { ServerResponse } from "http";
-//#endOverride
-
-//#override processInternalEvent
-export async function processInternalEvent<Response extends ServerResponse>(
-  internalEvent: InternalEvent,
-  createResponse: CreateResponse<Response>,
-): Promise<ProcessInternalEventResult<Response>> {
-  const reqProps = {
-    method: internalEvent.method,
-    url: internalEvent.url,
-    //WORKAROUND: We pass this header to the serverless function to mimic a prefetch request which will not trigger revalidation since we handle revalidation differently
-    // There is 3 way we can handle revalidation:
-    // 1. We could just let the revalidation go as normal, but due to race condtions the revalidation will be unreliable
-    // 2. We could alter the lastModified time of our cache to make next believe that the cache is fresh, but this could cause issues with stale data since the cdn will cache the stale data as if it was fresh
-    // 3. OUR CHOICE: We could pass a purpose prefetch header to the serverless function to make next believe that the request is a prefetch request and not trigger revalidation (This could potentially break in the future if next changes the behavior of prefetch requests)
-    headers: { ...internalEvent.headers, purpose: "prefetch" },
-    body: internalEvent.body,
-    remoteAddress: internalEvent.remoteAddress,
-  };
-  const req = new IncomingMessage(reqProps);
-  const res = createResponse(reqProps.method, {});
-  return { internalEvent, req, res, isExternalRewrite: false };
-}
-//#endOverride
-
-//#override postProcessResponse
-export async function postProcessResponse({
-  internalEvent,
-  req,
-  res,
-  isExternalRewrite,
-}: PostProcessOptions): Promise<InternalResult> {
-  const { statusCode, headers, isBase64Encoded, body } = convertRes(
-    res as ServerlessResponse,
-  );
-
-  debug("ServerResponse data", { statusCode, headers, isBase64Encoded, body });
-
-  if (!isExternalRewrite) {
-    fixCacheHeaderForHtmlPages(internalEvent.rawPath, headers);
-    fixSWRCacheHeader(headers);
-    addOpenNextHeader(headers);
-    fixISRHeaders(headers);
-
-    await revalidateIfRequired(
-      internalEvent.headers.host,
-      internalEvent.rawPath,
-      headers,
-      req,
-    );
-  }
-
-  return {
-    type: internalEvent.type,
-    statusCode,
-    headers,
-    body,
-    isBase64Encoded,
-  };
-}
-//#endOverride
diff --git a/packages/open-next/src/adapters/plugins/serverHandler.replacement.ts b/packages/open-next/src/adapters/plugins/serverHandler.replacement.ts
deleted file mode 100644
index 1b311b0c1..000000000
--- a/packages/open-next/src/adapters/plugins/serverHandler.replacement.ts
+++ /dev/null
@@ -1,29 +0,0 @@
-/*eslint-disable simple-import-sort/imports */
-import type { Options, PluginHandler } from "../types/next-types.js";
-import type { IncomingMessage } from "../http/request.js";
-import type { ServerlessResponse } from "../http/response.js";
-//#override imports
-
-import { proxyRequest } from "./routing/util.js";
-import { requestHandler, setNextjsPrebundledReact } from "./util.js";
-//#endOverride
-
-//#override handler
-export const handler: PluginHandler = async (
-  req: IncomingMessage,
-  res: ServerlessResponse,
-  options: Options,
-) => {
-  let { internalEvent } = options;
-
-  const { rawPath } = internalEvent;
-
-  if (options.isExternalRewrite) {
-    return proxyRequest(req, res);
-  } else {
-    setNextjsPrebundledReact(rawPath);
-    // Next Server
-    return requestHandler(req, res);
-  }
-};
-//#endOverride
diff --git a/packages/open-next/src/adapters/plugins/serverHandler.ts b/packages/open-next/src/adapters/plugins/serverHandler.ts
deleted file mode 100644
index 620e1e90a..000000000
--- a/packages/open-next/src/adapters/plugins/serverHandler.ts
+++ /dev/null
@@ -1,17 +0,0 @@
-import type { IncomingMessage } from "../http/request.js";
-import { ServerlessResponse } from "../http/response.js";
-import type { Options, PluginHandler } from "../types/next-types.js";
-//#override imports
-import { requestHandler, setNextjsPrebundledReact } from "./util.js";
-//#endOverride
-
-//#override handler
-export const handler: PluginHandler = async (
-  req: IncomingMessage,
-  res: ServerlessResponse,
-  options: Options,
-) => {
-  setNextjsPrebundledReact(options.internalEvent.rawPath);
-  return requestHandler(req, res);
-};
-//#endOverride
diff --git a/packages/open-next/src/adapters/plugins/streaming.replacement.ts b/packages/open-next/src/adapters/plugins/streaming.replacement.ts
deleted file mode 100644
index 7a3190247..000000000
--- a/packages/open-next/src/adapters/plugins/streaming.replacement.ts
+++ /dev/null
@@ -1,104 +0,0 @@
-/*eslint-disable simple-import-sort/imports */
-import type {
-  APIGatewayProxyEvent,
-  APIGatewayProxyEventV2,
-  CloudFrontRequestEvent,
-} from "aws-lambda";
-
-import { convertFrom } from "../event-mapper";
-import { debug } from "../logger";
-import type { ResponseStream } from "../types/aws-lambda";
-import type { WarmerEvent } from "../warmer-function";
-//#override imports
-import { StreamingServerResponse } from "../http/responseStreaming";
-import { processInternalEvent } from "./routing/default.js";
-import {
-  addOpenNextHeader,
-  fixCacheHeaderForHtmlPages,
-  fixISRHeaders,
-  fixSWRCacheHeader,
-  revalidateIfRequired,
-} from "./routing/util";
-import { CreateResponse } from "../types/plugin";
-//#endOverride
-
-//#override lambdaHandler
-export const lambdaHandler = awslambda.streamifyResponse(async function (
-  event:
-    | APIGatewayProxyEventV2
-    | CloudFrontRequestEvent
-    | APIGatewayProxyEvent
-    | WarmerEvent,
-  responseStream: ResponseStream,
-) {
-  debug("event", event);
-
-  // Handler warmer
-  if ("type" in event) {
-    // @ts-ignore formatWarmerResponse defined in lambdaHandler
-    const result = await formatWarmerResponse(event);
-    responseStream.end(Buffer.from(JSON.stringify(result)), "utf-8");
-    return;
-  }
-  // Parse Lambda event and create Next.js request
-  const internalEvent = convertFrom(event);
-
-  // WORKAROUND: Set `x-forwarded-host` header (AWS specific) — https://github.com/serverless-stack/open-next#workaround-set-x-forwarded-host-header-aws-specific
-  if (internalEvent.headers["x-forwarded-host"]) {
-    internalEvent.headers.host = internalEvent.headers["x-forwarded-host"];
-  }
-
-  const createServerResponse: CreateResponse<StreamingServerResponse> = (
-    method: string,
-    headers: Record<string, string | string[] | undefined>,
-  ) => {
-    // sets the accept-encoding for responseStreaming.ts to set "content-encoding"
-    headers["accept-encoding"] = internalEvent.headers["accept-encoding"];
-    return new StreamingServerResponse({
-      method,
-      headers,
-      responseStream,
-      // We need to fix the cache header before sending any response
-      fixHeaders: (headers) => {
-        fixCacheHeaderForHtmlPages(internalEvent.rawPath, headers);
-        fixSWRCacheHeader(headers);
-        addOpenNextHeader(headers);
-        fixISRHeaders(headers);
-      },
-      // This run in the callback of the response stream end
-      onEnd: async (headers) => {
-        await revalidateIfRequired(
-          internalEvent.headers.host,
-          internalEvent.rawPath,
-          headers,
-        );
-      },
-    });
-  };
-
-  const preprocessResult = await processInternalEvent(
-    internalEvent,
-    createServerResponse,
-  );
-  if ("type" in preprocessResult) {
-    const headers = preprocessResult.headers;
-    const res = createServerResponse("GET", headers);
-
-    setImmediate(() => {
-      res.writeHead(preprocessResult.statusCode, headers);
-      res.write(preprocessResult.body);
-      res.end();
-    });
-  } else {
-    const {
-      req,
-      res,
-      isExternalRewrite,
-      internalEvent: overwrittenInternalEvent,
-    } = preprocessResult;
-
-    //@ts-expect-error - processRequest is already defined in serverHandler.ts
-    await processRequest(req, res, overwrittenInternalEvent, isExternalRewrite);
-  }
-});
-//#endOverride
diff --git a/packages/open-next/src/adapters/plugins/util.replacement.ts b/packages/open-next/src/adapters/plugins/util.replacement.ts
deleted file mode 100644
index 6d44b404a..000000000
--- a/packages/open-next/src/adapters/plugins/util.replacement.ts
+++ /dev/null
@@ -1,25 +0,0 @@
-import { NextConfig } from "../config";
-
-//#override requestHandler
-// @ts-ignore
-export const requestHandler = new NextServer.default({
-  conf: {
-    ...NextConfig,
-    // Next.js compression should be disabled because of a bug in the bundled
-    // `compression` package — https://github.com/vercel/next.js/issues/11669
-    compress: false,
-    // By default, Next.js uses local disk to store ISR cache. We will use
-    // our own cache handler to store the cache on S3.
-    experimental: {
-      ...NextConfig.experimental,
-      // This uses the request.headers.host as the URL
-      // https://github.com/vercel/next.js/blob/canary/packages/next/src/server/next-server.ts#L1749-L1754
-      trustHostHeader: true,
-      incrementalCacheHandlerPath: `${process.env.LAMBDA_TASK_ROOT}/cache.cjs`,
-    },
-  },
-  customServer: false,
-  dev: false,
-  dir: __dirname,
-}).getRequestHandler();
-//#endOverride
diff --git a/packages/open-next/src/adapters/plugins/without-routing/requestHandler.ts b/packages/open-next/src/adapters/plugins/without-routing/requestHandler.ts
new file mode 100644
index 000000000..b5e879dbc
--- /dev/null
+++ b/packages/open-next/src/adapters/plugins/without-routing/requestHandler.ts
@@ -0,0 +1,14 @@
+import { InternalEvent } from "types/open-next";
+
+import { MiddlewareOutputEvent } from "../../../core/routingHandler";
+// This is available in requestHandler.ts
+declare const internalEvent: InternalEvent;
+
+//#override withRouting
+// eslint-disable-next-line unused-imports/no-unused-vars
+const preprocessResult: MiddlewareOutputEvent = {
+  internalEvent: internalEvent,
+  isExternalRewrite: false,
+  headers: {},
+};
+//#endOverride
diff --git a/packages/open-next/src/adapters/revalidate.ts b/packages/open-next/src/adapters/revalidate.ts
index 5014da2b8..471d4b1a7 100644
--- a/packages/open-next/src/adapters/revalidate.ts
+++ b/packages/open-next/src/adapters/revalidate.ts
@@ -3,8 +3,7 @@ import type { IncomingMessage } from "node:http";
 import https from "node:https";
 import path from "node:path";
 
-import type { SQSEvent } from "aws-lambda";
-
+import { createGenericHandler } from "../core/createGenericHandler.js";
 import { debug, error } from "./logger.js";
 
 const prerenderManifest = loadPrerenderManifest();
@@ -17,9 +16,17 @@ interface PrerenderManifest {
   };
 }
 
-export const handler = async (event: SQSEvent) => {
-  for (const record of event.Records) {
-    const { host, url } = JSON.parse(record.body);
+export interface RevalidateEvent {
+  type: "revalidate";
+  records: {
+    host: string;
+    url: string;
+  }[];
+}
+
+const defaultHandler = async (event: RevalidateEvent) => {
+  for (const record of event.records) {
+    const { host, url } = record;
     debug(`Revalidating stale page`, { host, url });
 
     // Make a HEAD request to the page to revalidate it. This will trigger
@@ -49,8 +56,16 @@ export const handler = async (event: SQSEvent) => {
       req.end();
     });
   }
+  return {
+    type: "revalidate",
+  };
 };
 
+export const handler = await createGenericHandler({
+  handler: defaultHandler,
+  type: "revalidate",
+});
+
 function loadPrerenderManifest() {
   const filePath = path.join("prerender-manifest.json");
   const json = fs.readFileSync(filePath, "utf-8");
diff --git a/packages/open-next/src/adapters/routing/util.ts b/packages/open-next/src/adapters/routing/util.ts
deleted file mode 100644
index eeef3cee9..000000000
--- a/packages/open-next/src/adapters/routing/util.ts
+++ /dev/null
@@ -1,76 +0,0 @@
-import fs from "node:fs";
-import path from "node:path";
-
-import { isBinaryContentType } from "../binary";
-import { ServerlessResponse } from "../http/response";
-import { MiddlewareManifest } from "../types/next-types";
-
-export function isExternal(url?: string, host?: string) {
-  if (!url) return false;
-  const pattern = /^https?:\/\//;
-  if (host) {
-    return pattern.test(url) && !url.includes(host);
-  }
-  return pattern.test(url);
-}
-
-export function getUrlParts(url: string, isExternal: boolean) {
-  // NOTE: when redirect to a URL that contains search query params,
-  // compile breaks b/c it does not allow for the '?' character
-  // We can't use encodeURIComponent because modal interception contains
-  // characters that can't be encoded
-  url = url.replaceAll("?", "%3F");
-  if (!isExternal) {
-    return {
-      hostname: "",
-      pathname: url,
-      protocol: "",
-    };
-  }
-  const { hostname, pathname, protocol } = new URL(url);
-  return {
-    hostname,
-    pathname,
-    protocol,
-  };
-}
-
-export function convertRes(res: ServerlessResponse) {
-  // Format Next.js response to Lambda response
-  const statusCode = res.statusCode || 200;
-  const headers = ServerlessResponse.headers(res);
-  const isBase64Encoded = isBinaryContentType(
-    Array.isArray(headers["content-type"])
-      ? headers["content-type"][0]
-      : headers["content-type"],
-  );
-  const encoding = isBase64Encoded ? "base64" : "utf8";
-  const body = ServerlessResponse.body(res).toString(encoding);
-  return {
-    statusCode,
-    headers,
-    body,
-    isBase64Encoded,
-  };
-}
-
-export function convertQuery(query: Record<string, string | string[]>) {
-  const urlQuery: Record<string, string> = {};
-  Object.keys(query).forEach((k) => {
-    const v = query[k];
-    urlQuery[k] = Array.isArray(v) ? v.join(",") : v;
-  });
-  return urlQuery;
-}
-
-export function getMiddlewareMatch(middlewareManifest: MiddlewareManifest) {
-  const rootMiddleware = middlewareManifest.middleware["/"];
-  if (!rootMiddleware?.matchers) return [];
-  return rootMiddleware.matchers.map(({ regexp }) => new RegExp(regexp));
-}
-
-export function loadMiddlewareManifest(nextDir: string) {
-  const filePath = path.join(nextDir, "server", "middleware-manifest.json");
-  const json = fs.readFileSync(filePath, "utf-8");
-  return JSON.parse(json) as MiddlewareManifest;
-}
diff --git a/packages/open-next/src/adapters/server-adapter.ts b/packages/open-next/src/adapters/server-adapter.ts
index 6c26cf541..3fa6df50a 100644
--- a/packages/open-next/src/adapters/server-adapter.ts
+++ b/packages/open-next/src/adapters/server-adapter.ts
@@ -1,9 +1,8 @@
-import { DynamoDBClient, DynamoDBClientConfig } from "@aws-sdk/client-dynamodb";
-import { S3Client, S3ClientConfig } from "@aws-sdk/client-s3";
+// We load every config here so that they are only loaded once
+// and during cold starts
+import { BuildId } from "config/index.js";
 
-import { BuildId } from "./config/index.js";
-import { awsLogger } from "./logger.js";
-import { lambdaHandler } from "./plugins/lambdaHandler.js";
+import { createMainHandler } from "../core/createMainHandler.js";
 import { setNodeEnv } from "./util.js";
 
 // We load every config here so that they are only loaded once
@@ -12,57 +11,11 @@ setNodeEnv();
 setBuildIdEnv();
 setNextjsServerWorkingDirectory();
 
-////////////////////////
-// AWS global clients //
-////////////////////////
-
-declare global {
-  var S3Client: S3Client;
-  var dynamoClient: DynamoDBClient;
-}
-
-const CACHE_BUCKET_REGION = process.env.CACHE_BUCKET_REGION;
-
-function parseS3ClientConfigFromEnv(): S3ClientConfig {
-  return {
-    region: CACHE_BUCKET_REGION,
-    logger: awsLogger,
-    maxAttempts: parseNumberFromEnv(process.env.AWS_SDK_S3_MAX_ATTEMPTS),
-  };
-}
-
-function parseDynamoClientConfigFromEnv(): DynamoDBClientConfig {
-  return {
-    region: CACHE_BUCKET_REGION,
-    logger: awsLogger,
-    maxAttempts: parseNumberFromEnv(process.env.AWS_SDK_DYNAMODB_MAX_ATTEMPTS),
-  };
-}
-
-function parseNumberFromEnv(envValue: string | undefined): number | undefined {
-  if (typeof envValue !== "string") {
-    return envValue;
-  }
-
-  const parsedValue = parseInt(envValue);
-
-  return isNaN(parsedValue) ? undefined : parsedValue;
-}
-
-// Cache clients using global variables
-// Note: The clients are used in `cache.ts`. The incremental cache is recreated on
-//       every request and required on every request (And the require cache is also
-//       cleared). It was causing some file to stay open which after enough time
-//       would cause the function to crash with error "EMFILE too many open". It
-//       was also making the memory grow out of control.
-globalThis.S3Client = new S3Client(parseS3ClientConfigFromEnv());
-globalThis.dynamoClient = new DynamoDBClient(parseDynamoClientConfigFromEnv());
-
 /////////////
 // Handler //
 /////////////
 
-export const handler = lambdaHandler;
+export const handler = await createMainHandler();
 
 //////////////////////
 // Helper functions //
diff --git a/packages/open-next/src/adapters/types/plugin.ts b/packages/open-next/src/adapters/types/plugin.ts
deleted file mode 100644
index 47c7ed3a0..000000000
--- a/packages/open-next/src/adapters/types/plugin.ts
+++ /dev/null
@@ -1,36 +0,0 @@
-import type { ServerResponse } from "http";
-
-import type { InternalEvent, InternalResult } from "../event-mapper";
-import type { IncomingMessage } from "../http/request";
-
-export type ProcessInternalEventResult<
-  Response extends ServerResponse = ServerResponse,
-> =
-  | {
-      internalEvent: InternalEvent;
-      req: IncomingMessage;
-      res: Response;
-      isExternalRewrite: boolean;
-    }
-  | InternalResult;
-
-export type ProcessInternalEvent<
-  Response extends ServerResponse = ServerResponse,
-> = (
-  internalEvent: InternalEvent,
-  createResponse: CreateResponse<Response>,
-) => Promise<ProcessInternalEventResult<Response>>;
-
-export interface PostProcessOptions<
-  Response extends ServerResponse = ServerResponse,
-> {
-  internalEvent: InternalEvent;
-  req: IncomingMessage;
-  res: Response;
-  isExternalRewrite?: boolean;
-}
-
-export type CreateResponse<Response extends ServerResponse = ServerResponse> = (
-  method: string,
-  headers: Record<string, string | string[] | undefined>,
-) => Response;
diff --git a/packages/open-next/src/adapters/util.ts b/packages/open-next/src/adapters/util.ts
index aca13a2c8..d35545e89 100644
--- a/packages/open-next/src/adapters/util.ts
+++ b/packages/open-next/src/adapters/util.ts
@@ -1,3 +1,5 @@
+//TODO: We should probably move all the utils to a separate location
+
 export function setNodeEnv() {
   process.env.NODE_ENV = process.env.NODE_ENV ?? "production";
 }
@@ -6,39 +8,6 @@ export function generateUniqueId() {
   return Math.random().toString(36).slice(2, 8);
 }
 
-export function escapeRegex(str: string) {
-  let path = str.replace(/\(\.\)/g, "_µ1_");
-
-  path = path.replace(/\(\.{2}\)/g, "_µ2_");
-
-  path = path.replace(/\(\.{3}\)/g, "_µ3_");
-
-  return path;
-}
-
-export function unescapeRegex(str: string) {
-  let path = str.replace(/_µ1_/g, "(.)");
-
-  path = path.replace(/_µ2_/g, "(..)");
-
-  path = path.replace(/_µ3_/g, "(...)");
-
-  return path;
-}
-
-// AWS cookies are in a single `set-cookie` string, delimited by a comma
-export function parseCookies(
-  cookies?: string | string[],
-): string[] | undefined {
-  if (!cookies) return;
-
-  if (typeof cookies === "string") {
-    return cookies.split(/(?<!Expires=\w+),/i).map((c) => c.trim());
-  }
-
-  return cookies;
-}
-
 /**
  * Create an array of arrays of size `chunkSize` from `items`
  * @param items Array of T
@@ -54,3 +23,15 @@ export function chunk<T>(items: T[], chunkSize: number): T[][] {
 
   return chunked;
 }
+
+export function parseNumberFromEnv(
+  envValue: string | undefined,
+): number | undefined {
+  if (typeof envValue !== "string") {
+    return envValue;
+  }
+
+  const parsedValue = parseInt(envValue);
+
+  return isNaN(parsedValue) ? undefined : parsedValue;
+}
diff --git a/packages/open-next/src/adapters/warmer-function.ts b/packages/open-next/src/adapters/warmer-function.ts
index 4ee564fae..95a1d6224 100644
--- a/packages/open-next/src/adapters/warmer-function.ts
+++ b/packages/open-next/src/adapters/warmer-function.ts
@@ -1,6 +1,6 @@
 import { InvokeCommand, LambdaClient } from "@aws-sdk/client-lambda";
-import type { Context } from "aws-lambda";
 
+import { createGenericHandler } from "../core/createGenericHandler.js";
 import { debug, error } from "./logger.js";
 import { generateUniqueId } from "./util.js";
 
@@ -17,10 +17,69 @@ export interface WarmerEvent {
 }
 
 export interface WarmerResponse {
+  type: "warmer";
   serverId: string;
 }
 
-export async function handler(_event: any, context: Context) {
+const resolveWarmerInvoke = async () => {
+  const openNextParams = globalThis.openNextConfig.warmer!;
+  if (typeof openNextParams?.invokeFunction === "function") {
+    return await openNextParams.invokeFunction();
+  } else {
+    return Promise.resolve(async (warmerId: string) => {
+      const ret = await Promise.all(
+        Array.from({ length: CONCURRENCY }, (_v, i) => i).map((i) => {
+          try {
+            return lambda.send(
+              new InvokeCommand({
+                FunctionName: FUNCTION_NAME,
+                InvocationType: "RequestResponse",
+                Payload: Buffer.from(
+                  JSON.stringify({
+                    type: "warmer",
+                    warmerId,
+                    index: i,
+                    concurrency: CONCURRENCY,
+                    delay: 75,
+                  } satisfies WarmerEvent),
+                ),
+              }),
+            );
+          } catch (e) {
+            error(`failed to warm up #${i}`, e);
+            // ignore error
+          }
+        }),
+      );
+
+      // Print status
+
+      return ret
+        .map((r, i) => {
+          if (r?.StatusCode !== 200 || !r?.Payload) {
+            error(`failed to warm up #${i}:`, r?.Payload?.toString());
+            return;
+          }
+          const payload = JSON.parse(
+            Buffer.from(r.Payload).toString(),
+          ) as WarmerResponse;
+          return {
+            statusCode: r.StatusCode,
+            payload,
+            type: "warmer" as const,
+          };
+        })
+        .filter((r): r is Exclude<typeof r, undefined> => !!r);
+    });
+  }
+};
+
+export const handler = await createGenericHandler({
+  handler: defaultHandler,
+  type: "warmer",
+});
+
+async function defaultHandler() {
   const warmerId = `warmer-${generateUniqueId()}`;
   debug({
     event: "warmer invoked",
@@ -29,48 +88,17 @@ export async function handler(_event: any, context: Context) {
     warmerId,
   });
 
-  // Warm
-  const ret = await Promise.all(
-    Array.from({ length: CONCURRENCY }, (_v, i) => i).map((i) => {
-      try {
-        return lambda.send(
-          new InvokeCommand({
-            FunctionName: FUNCTION_NAME,
-            InvocationType: "RequestResponse",
-            Payload: Buffer.from(
-              JSON.stringify({
-                type: "warmer",
-                warmerId,
-                index: i,
-                concurrency: CONCURRENCY,
-                delay: 75,
-              } satisfies WarmerEvent),
-            ),
-          }),
-        );
-      } catch (e) {
-        error(`failed to warm up #${i}`, e);
-        // ignore error
-      }
-    }),
-  );
+  const invokeFn = await resolveWarmerInvoke();
+
+  const warmedServerIds = await invokeFn(warmerId);
 
-  // Print status
-  const warmedServerIds: string[] = [];
-  ret.forEach((r, i) => {
-    if (r?.StatusCode !== 200 || !r?.Payload) {
-      error(`failed to warm up #${i}:`, r?.Payload?.toString());
-      return;
-    }
-    const payload = JSON.parse(
-      Buffer.from(r.Payload).toString(),
-    ) as WarmerResponse;
-    warmedServerIds.push(payload.serverId);
-  });
   debug({
     event: "warmer result",
     sent: CONCURRENCY,
     success: warmedServerIds.length,
     uniqueServersWarmed: [...new Set(warmedServerIds)].length,
   });
+  return {
+    type: "warmer",
+  };
 }
diff --git a/packages/open-next/src/build.ts b/packages/open-next/src/build.ts
index 929a88fdb..c4319623a 100644
--- a/packages/open-next/src/build.ts
+++ b/packages/open-next/src/build.ts
@@ -1,5 +1,5 @@
 import cp from "node:child_process";
-import fs from "node:fs";
+import fs, { readFileSync } from "node:fs";
 import { createRequire as topLevelCreateRequire } from "node:module";
 import path from "node:path";
 import url from "node:url";
@@ -12,63 +12,10 @@ import {
 
 import logger from "./logger.js";
 import { minifyAll } from "./minimize-js.js";
-import openNextPlugin from "./plugin.js";
-
-interface DangerousOptions {
-  /**
-   * The dynamo db cache is used for revalidateTags and revalidatePath.
-   * @default false
-   */
-  disableDynamoDBCache?: boolean;
-  /**
-   * The incremental cache is used for ISR and SSG.
-   * Disable this only if you use only SSR
-   * @default false
-   */
-  disableIncrementalCache?: boolean;
-}
-interface BuildOptions {
-  /**
-   * Minify the server bundle.
-   * @default false
-   */
-  minify?: boolean;
-  /**
-   * Print debug information.
-   * @default false
-   */
-  debug?: boolean;
-  /**
-   * Enable streaming mode.
-   * @default false
-   */
-  streaming?: boolean;
-  /**
-   * The command to build the Next.js app.
-   * @default `npm run build`, `yarn build`, or `pnpm build` based on the lock file found in the app's directory or any of its parent directories.
-   * @example
-   * ```ts
-   * build({
-   *   buildCommand: "pnpm custom:build",
-   * });
-   * ```
-   */
-  /**
-   * Dangerous options. This break some functionnality but can be useful in some cases.
-   */
-  dangerous?: DangerousOptions;
-  buildCommand?: string;
-  /**
-   * The path to the target folder of build output from the `buildCommand` option (the path which will contain the `.next` and `.open-next` folders). This path is relative from the current process.cwd().
-   * @default "."
-   */
-  buildOutputPath?: string;
-  /**
-   * The path to the root of the Next.js app's source code. This path is relative from the current process.cwd().
-   * @default "."
-   */
-  appPath?: string;
-}
+import { openNextEdgePlugins } from "./plugins/edge.js";
+import { openNextReplacementPlugin } from "./plugins/replacement.js";
+import { openNextResolvePlugin } from "./plugins/resolve.js";
+import { BuildOptions, DangerousOptions } from "./types/open-next.js";
 
 const require = topLevelCreateRequire(import.meta.url);
 const __dirname = url.fileURLToPath(new URL(".", import.meta.url));
@@ -78,7 +25,13 @@ export type PublicFiles = {
   files: string[];
 };
 
-export async function build(opts: BuildOptions = {}) {
+export async function build(
+  opts: BuildOptions = {
+    functions: {
+      default: {},
+    },
+  },
+) {
   const { root: monorepoRoot, packager } = findMonorepoRoot(
     path.join(process.cwd(), opts.appPath || "."),
   );
@@ -100,19 +53,33 @@ export async function build(opts: BuildOptions = {}) {
   // Generate deployable bundle
   printHeader("Generating bundle");
   initOutputDir();
+  createOpenNextConfigBundle(options.tempDir);
   createStaticAssets();
   if (!options.dangerous?.disableIncrementalCache) {
-    createCacheAssets(monorepoRoot, options.dangerous?.disableDynamoDBCache);
+    await createCacheAssets(
+      monorepoRoot,
+      options.dangerous?.disableDynamoDBCache,
+    );
   }
-  await createServerBundle(monorepoRoot, options.streaming);
-  createRevalidationBundle();
+  await createServerBundle(monorepoRoot, opts);
+  await createRevalidationBundle();
   createImageOptimizationBundle();
-  createWarmerBundle();
+  await createWarmerBundle();
   if (options.minify) {
     await minifyServerBundle();
   }
 }
 
+function createOpenNextConfigBundle(tempDir: string) {
+  esbuildSync({
+    entryPoints: [path.join(process.cwd(), "open-next.config.ts")],
+    outfile: path.join(tempDir, "open-next.config.js"),
+    bundle: true,
+    format: "cjs",
+    target: ["node18"],
+  });
+}
+
 function normalizeOptions(opts: BuildOptions, root: string) {
   const appPath = path.join(process.cwd(), opts.appPath || ".");
   const buildOutputPath = path.join(process.cwd(), opts.buildOutputPath || ".");
@@ -127,11 +94,18 @@ function normalizeOptions(opts: BuildOptions, root: string) {
     appPublicPath: path.join(appPath, "public"),
     outputDir,
     tempDir: path.join(outputDir, ".build"),
-    minify: opts.minify ?? Boolean(process.env.OPEN_NEXT_MINIFY) ?? false,
-    debug: opts.debug ?? Boolean(process.env.OPEN_NEXT_DEBUG) ?? false,
+    minify:
+      opts.functions.default.minify ??
+      Boolean(process.env.OPEN_NEXT_MINIFY) ??
+      false,
+    debug:
+      opts.functions.default.debug ??
+      Boolean(process.env.OPEN_NEXT_DEBUG) ??
+      false,
     buildCommand: opts.buildCommand,
     dangerous: opts.dangerous,
-    streaming: opts.streaming ?? false,
+    streaming: opts.functions.default.streaming ?? false,
+    externalMiddleware: opts.middleware?.external ?? false,
   };
 }
 
@@ -237,7 +211,7 @@ function initOutputDir() {
   fs.mkdirSync(tempDir, { recursive: true });
 }
 
-function createWarmerBundle() {
+async function createWarmerBundle() {
   logger.info(`Bundling warmer function...`);
 
   const { outputDir } = options;
@@ -246,14 +220,27 @@ function createWarmerBundle() {
   const outputPath = path.join(outputDir, "warmer-function");
   fs.mkdirSync(outputPath, { recursive: true });
 
+  // Copy open-next.config.js into the bundle
+  fs.copyFileSync(
+    path.join(options.tempDir, "open-next.config.js"),
+    path.join(outputPath, "open-next.config.js"),
+  );
+
   // Build Lambda code
   // note: bundle in OpenNext package b/c the adatper relys on the
   //       "serverless-http" package which is not a dependency in user's
   //       Next.js app.
-  esbuildSync({
+  await esbuildAsync({
     entryPoints: [path.join(__dirname, "adapters", "warmer-function.js")],
     external: ["next"],
     outfile: path.join(outputPath, "index.mjs"),
+    plugins: [
+      openNextResolvePlugin({
+        overrides: {
+          converter: "dummy",
+        },
+      }),
+    ],
     banner: {
       js: [
         "import { createRequire as topLevelCreateRequire } from 'module';",
@@ -274,7 +261,7 @@ async function minifyServerBundle() {
   });
 }
 
-function createRevalidationBundle() {
+async function createRevalidationBundle() {
   logger.info(`Bundling revalidation function...`);
 
   const { appBuildOutputPath, outputDir } = options;
@@ -283,11 +270,24 @@ function createRevalidationBundle() {
   const outputPath = path.join(outputDir, "revalidation-function");
   fs.mkdirSync(outputPath, { recursive: true });
 
+  //Copy open-next.config.js into the bundle
+  fs.copyFileSync(
+    path.join(options.tempDir, "open-next.config.js"),
+    path.join(outputPath, "open-next.config.js"),
+  );
+
   // Build Lambda code
-  esbuildSync({
+  esbuildAsync({
     external: ["next", "styled-jsx", "react"],
     entryPoints: [path.join(__dirname, "adapters", "revalidate.js")],
     outfile: path.join(outputPath, "index.mjs"),
+    plugins: [
+      openNextResolvePlugin({
+        overrides: {
+          converter: "sqs-revalidate",
+        },
+      }),
+    ],
   });
 
   // Copy over .next/prerender-manifest.json file
@@ -306,6 +306,12 @@ function createImageOptimizationBundle() {
   const outputPath = path.join(outputDir, "image-optimization-function");
   fs.mkdirSync(outputPath, { recursive: true });
 
+  // Copy open-next.config.js into the bundle
+  fs.copyFileSync(
+    path.join(options.tempDir, "open-next.config.js"),
+    path.join(outputPath, "open-next.config.js"),
+  );
+
   // Build Lambda code (1st pass)
   // note: bundle in OpenNext package b/c the adapter relies on the
   //       "@aws-sdk/client-s3" package which is not a dependency in user's
@@ -410,7 +416,10 @@ function createStaticAssets() {
   }
 }
 
-function createCacheAssets(monorepoRoot: string, disableDynamoDBCache = false) {
+async function createCacheAssets(
+  monorepoRoot: string,
+  disableDynamoDBCache = false,
+) {
   logger.info(`Bundling cache assets...`);
 
   const { appBuildOutputPath, outputDir } = options;
@@ -569,13 +578,26 @@ function createCacheAssets(monorepoRoot: string, disableDynamoDBCache = false) {
     if (metaFiles.length > 0) {
       const providerPath = path.join(outputDir, "dynamodb-provider");
 
-      esbuildSync({
+      await esbuildAsync({
         external: ["@aws-sdk/client-dynamodb"],
         entryPoints: [path.join(__dirname, "adapters", "dynamo-provider.js")],
         outfile: path.join(providerPath, "index.mjs"),
         target: ["node18"],
+        plugins: [
+          openNextResolvePlugin({
+            overrides: {
+              converter: "dummy",
+            },
+          }),
+        ],
       });
 
+      //Copy open-next.config.js into the bundle
+      fs.copyFileSync(
+        path.join(options.tempDir, "open-next.config.js"),
+        path.join(providerPath, "open-next.config.js"),
+      );
+
       // TODO: check if metafiles doesn't contain duplicates
       fs.writeFileSync(
         path.join(providerPath, "dynamodb-cache.json"),
@@ -589,7 +611,10 @@ function createCacheAssets(monorepoRoot: string, disableDynamoDBCache = false) {
 /* Server Helper Functions */
 /***************************/
 
-async function createServerBundle(monorepoRoot: string, streaming = false) {
+async function createServerBundle(
+  monorepoRoot: string,
+  buildOptions: BuildOptions,
+) {
   logger.info(`Bundling server function...`);
 
   const { appPath, appBuildOutputPath, outputDir } = options;
@@ -606,6 +631,17 @@ async function createServerBundle(monorepoRoot: string, streaming = false) {
   const isMonorepo = monorepoRoot !== appPath;
   const packagePath = path.relative(monorepoRoot, appBuildOutputPath);
 
+  // Copy open-next.config.js
+  // We should reuse the one we created at the beginning of the build
+  fs.mkdirSync(path.join(outputPath, packagePath), { recursive: true });
+  fs.copyFileSync(
+    path.join(options.tempDir, "open-next.config.js"),
+    path.join(outputPath, packagePath, "open-next.config.js"),
+  );
+
+  // Bundle middleware
+  createMiddleware(packagePath);
+
   // Copy over standalone output files
   // note: if user uses pnpm as the package manager, node_modules contain
   //       symlinks. We don't want to resolve the symlinks when copying.
@@ -623,59 +659,51 @@ async function createServerBundle(monorepoRoot: string, streaming = false) {
   //       "serverless-http" package which is not a dependency in user's
   //       Next.js app.
 
-  let plugins =
-    compareSemver(options.nextVersion, "13.4.13") >= 0
-      ? [
-          openNextPlugin({
-            name: "opennext-13.4.13-serverHandler",
-            target: /plugins\/serverHandler\.js/g,
-            replacements: ["./serverHandler.replacement.js"],
-          }),
-          openNextPlugin({
-            name: "opennext-13.4.13-util",
-            target: /plugins\/util\.js/g,
-            replacements: ["./util.replacement.js"],
-          }),
-          openNextPlugin({
-            name: "opennext-13.4.13-default",
-            target: /plugins\/routing\/default\.js/g,
-            replacements: ["./default.replacement.js"],
-          }),
-        ]
-      : undefined;
-
-  if (compareSemver(options.nextVersion, "13.5.1") >= 0) {
-    plugins = [
-      openNextPlugin({
-        name: "opennext-13.5-serverHandler",
-        target: /plugins\/serverHandler\.js/g,
-        replacements: ["./13.5/serverHandler.js"],
-      }),
-      openNextPlugin({
-        name: "opennext-13.5-util",
-        target: /plugins\/util\.js/g,
-        replacements: ["./13.5/util.js", "./util.replacement.js"],
-      }),
-      openNextPlugin({
-        name: "opennext-13.5-default",
-        target: /plugins\/routing\/default\.js/g,
-        replacements: ["./default.replacement.js"],
-      }),
-    ];
-  }
-
-  if (streaming) {
-    const streamingPlugin = openNextPlugin({
-      name: "opennext-streaming",
-      target: /plugins\/lambdaHandler\.js/g,
-      replacements: ["./streaming.replacement.js"],
-    });
-    if (plugins) {
-      plugins.push(streamingPlugin);
-    } else {
-      plugins = [streamingPlugin];
-    }
-  }
+  const disableNextPrebundledReact =
+    compareSemver(options.nextVersion, "13.5.1") >= 0 ||
+    compareSemver(options.nextVersion, "13.4.1") <= 0;
+
+  const overrides = buildOptions.functions.default.override ?? {};
+
+  const isBefore13413 = compareSemver(options.nextVersion, "13.4.13") <= 0;
+
+  const disableRouting = isBefore13413 || options.externalMiddleware;
+  const plugins = [
+    openNextReplacementPlugin({
+      name: "requestHandlerOverride",
+      target: /core\/requestHandler.js/g,
+      deletes: disableNextPrebundledReact ? ["applyNextjsPrebundledReact"] : [],
+      replacements: disableRouting
+        ? [
+            require.resolve(
+              "./adapters/plugins/without-routing/requestHandler.js",
+            ),
+          ]
+        : [],
+    }),
+    openNextReplacementPlugin({
+      name: "core/util",
+      target: /core\/util.js/g,
+      deletes: [
+        ...(disableNextPrebundledReact ? ["requireHooks"] : []),
+        ...(disableRouting ? ["trustHostHeader"] : []),
+        ...(!isBefore13413 ? ["requestHandlerHost"] : []),
+      ],
+    }),
+
+    openNextResolvePlugin({
+      overrides: {
+        converter:
+          typeof overrides.converter === "function"
+            ? "dummy"
+            : overrides.converter,
+        wrapper:
+          typeof overrides.wrapper === "function"
+            ? "aws-lambda"
+            : overrides.wrapper,
+      },
+    }),
+  ];
 
   if (plugins && plugins.length > 0) {
     logger.debug(
@@ -686,7 +714,7 @@ async function createServerBundle(monorepoRoot: string, streaming = false) {
   }
   await esbuildAsync({
     entryPoints: [path.join(__dirname, "adapters", "server-adapter.js")],
-    external: ["next"],
+    external: ["next", "./middleware.mjs"],
     outfile: path.join(outputPath, packagePath, "index.mjs"),
     banner: {
       js: [
@@ -709,6 +737,114 @@ async function createServerBundle(monorepoRoot: string, streaming = false) {
   addCacheHandler(outputPath, options.dangerous);
 }
 
+async function createMiddleware(packagePath: string) {
+  console.info(`Bundling middleware function...`);
+
+  const { appBuildOutputPath, outputDir, externalMiddleware } = options;
+
+  // Get middleware manifest
+  const middlewareManifest = JSON.parse(
+    readFileSync(
+      path.join(appBuildOutputPath, ".next/server/middleware-manifest.json"),
+      "utf8",
+    ),
+  );
+
+  const entry = middlewareManifest.middleware["/"];
+  if (!entry) {
+    return;
+  }
+
+  // Create output folder
+  let outputPath = path.join(outputDir, "server-function");
+  if (externalMiddleware) {
+    outputPath = path.join(outputDir, "middleware");
+    fs.mkdirSync(outputPath, { recursive: true });
+
+    // Copy open-next.config.js
+    fs.copyFileSync(
+      path.join(options.tempDir, "open-next.config.js"),
+      path.join(outputPath, "open-next.config.js"),
+    );
+
+    // Bundle middleware
+    await esbuildAsync({
+      entryPoints: [path.join(__dirname, "adapters", "middleware.js")],
+      // inject: ,
+      bundle: true,
+      outfile: path.join(outputPath, packagePath, "handler.mjs"),
+      external: ["node:*", "next", "@aws-sdk/*"],
+      target: "es2022",
+      platform: "neutral",
+      plugins: [
+        openNextResolvePlugin({
+          overrides: {
+            wrapper: "cloudflare",
+            converter: "edge",
+          },
+        }),
+        openNextEdgePlugins({
+          entryFiles: entry.files.map((file: string) =>
+            path.join(appBuildOutputPath, ".next", file),
+          ),
+          nextDir: path.join(appBuildOutputPath, ".next"),
+          edgeFunctionHandlerPath: path.join(
+            __dirname,
+            "core",
+            "edgeFunctionHandler.js",
+          ),
+        }),
+      ],
+      treeShaking: true,
+      alias: {
+        path: "node:path",
+        stream: "node:stream",
+      },
+      conditions: ["module"],
+      mainFields: ["module", "main"],
+    });
+  } else {
+    buildEdgeFunction(
+      entry,
+      path.join(__dirname, "core", "edgeFunctionHandler.js"),
+      path.join(outputPath, packagePath, "middleware.mjs"),
+      appBuildOutputPath,
+    );
+  }
+}
+
+function buildEdgeFunction(
+  entry: any,
+  entrypoint: string,
+  outfile: string,
+  appBuildOutputPath: string,
+) {
+  esbuildSync({
+    entryPoints: [entrypoint],
+    inject: entry.files.map((file: string) =>
+      path.join(appBuildOutputPath, ".next", file),
+    ),
+    bundle: true,
+    outfile,
+    external: ["node:*"],
+    target: "es2022",
+    platform: "neutral",
+    banner: {
+      js: `
+globalThis._ENTRIES = {};
+globalThis.self = globalThis;
+
+import {Buffer} from "node:buffer";
+globalThis.Buffer = Buffer;
+
+import {AsyncLocalStorage} from "node:async_hooks";
+globalThis.AsyncLocalStorage = AsyncLocalStorage;
+
+`,
+    },
+  });
+}
+
 function addMonorepoEntrypoint(outputPath: string, packagePath: string) {
   // Note: in the monorepo case, the handler file is output to
   //       `.next/standalone/package/path/index.mjs`, but we want
@@ -848,6 +984,7 @@ function esbuildSync(esbuildOptions: ESBuildOptions) {
     minify: debug ? false : true,
     sourcemap: debug ? "inline" : false,
     ...esbuildOptions,
+    external: ["./open-next.config.js", ...(esbuildOptions.external ?? [])],
     banner: {
       ...esbuildOptions.banner,
       js: [
@@ -878,6 +1015,11 @@ async function esbuildAsync(esbuildOptions: ESBuildOptions) {
     minify: debug ? false : true,
     sourcemap: debug ? "inline" : false,
     ...esbuildOptions,
+    external: [
+      ...(esbuildOptions.external ?? []),
+      "next",
+      "./open-next.config.js",
+    ],
     banner: {
       ...esbuildOptions.banner,
       js: [
diff --git a/packages/open-next/src/cache/incremental/s3.ts b/packages/open-next/src/cache/incremental/s3.ts
new file mode 100644
index 000000000..592d4fead
--- /dev/null
+++ b/packages/open-next/src/cache/incremental/s3.ts
@@ -0,0 +1,77 @@
+import {
+  DeleteObjectCommand,
+  GetObjectCommand,
+  PutObjectCommand,
+  S3Client,
+  S3ClientConfig,
+} from "@aws-sdk/client-s3";
+import path from "path";
+
+import { awsLogger } from "../../adapters/logger";
+import { parseNumberFromEnv } from "../../adapters/util";
+import { Extension } from "../next-types";
+import { IncrementalCache } from "./types";
+
+const {
+  CACHE_BUCKET_REGION,
+  CACHE_BUCKET_KEY_PREFIX,
+  NEXT_BUILD_ID,
+  CACHE_BUCKET_NAME,
+} = process.env;
+
+function parseS3ClientConfigFromEnv(): S3ClientConfig {
+  return {
+    region: CACHE_BUCKET_REGION,
+    logger: awsLogger,
+    maxAttempts: parseNumberFromEnv(process.env.AWS_SDK_S3_MAX_ATTEMPTS),
+  };
+}
+
+const s3Client = new S3Client(parseS3ClientConfigFromEnv());
+
+function buildS3Key(key: string, extension: Extension) {
+  return path.posix.join(
+    CACHE_BUCKET_KEY_PREFIX ?? "",
+    extension === "fetch" ? "__fetch" : "",
+    NEXT_BUILD_ID ?? "",
+    extension === "fetch" ? key : `${key}.${extension}`,
+  );
+}
+
+const incrementalCache: IncrementalCache = {
+  async get(key, isFetch) {
+    const result = await s3Client.send(
+      new GetObjectCommand({
+        Bucket: CACHE_BUCKET_NAME,
+        Key: buildS3Key(key, isFetch ? "fetch" : "cache"),
+      }),
+    );
+
+    const cacheData = JSON.parse(
+      (await result.Body?.transformToString()) ?? "{}",
+    );
+    return {
+      value: cacheData,
+      lastModified: result.LastModified?.getTime(),
+    };
+  },
+  async set(key, value, isFetch): Promise<void> {
+    await s3Client.send(
+      new PutObjectCommand({
+        Bucket: CACHE_BUCKET_NAME,
+        Key: buildS3Key(key, isFetch ? "fetch" : "cache"),
+        Body: JSON.stringify(value),
+      }),
+    );
+  },
+  async delete(key): Promise<void> {
+    await s3Client.send(
+      new DeleteObjectCommand({
+        Bucket: CACHE_BUCKET_NAME,
+        Key: buildS3Key(key, "cache"),
+      }),
+    );
+  },
+};
+
+export default incrementalCache;
diff --git a/packages/open-next/src/cache/incremental/types.ts b/packages/open-next/src/cache/incremental/types.ts
new file mode 100644
index 000000000..c2a4468de
--- /dev/null
+++ b/packages/open-next/src/cache/incremental/types.ts
@@ -0,0 +1,49 @@
+import { Meta } from "../next-types";
+
+export type S3CachedFile =
+  | {
+      type: "redirect";
+      props?: Object;
+      meta?: Meta;
+    }
+  | {
+      type: "page";
+      html: string;
+      json: Object;
+      meta?: Meta;
+    }
+  | {
+      type: "app";
+      html: string;
+      rsc: string;
+      meta?: Meta;
+    }
+  | {
+      type: "route";
+      body: string;
+      meta?: Meta;
+    };
+
+export type S3FetchCache = Object;
+
+export type WithLastModified<T> = {
+  lastModified?: number;
+  value?: T;
+};
+
+export type CacheValue<IsFetch extends boolean> = IsFetch extends true
+  ? S3FetchCache
+  : S3CachedFile;
+
+export type IncrementalCache = {
+  get<IsFetch extends boolean = false>(
+    key: string,
+    isFetch?: IsFetch,
+  ): Promise<WithLastModified<CacheValue<IsFetch>>>;
+  set<IsFetch extends boolean = false>(
+    key: string,
+    value: CacheValue<IsFetch>,
+    isFetch?: IsFetch,
+  ): Promise<void>;
+  delete(key: string): Promise<void>;
+};
diff --git a/packages/open-next/src/cache/next-types.ts b/packages/open-next/src/cache/next-types.ts
new file mode 100644
index 000000000..58fe95652
--- /dev/null
+++ b/packages/open-next/src/cache/next-types.ts
@@ -0,0 +1,76 @@
+interface CachedFetchValue {
+  kind: "FETCH";
+  data: {
+    headers: { [k: string]: string };
+    body: string;
+    url: string;
+    status?: number;
+    tags?: string[];
+  };
+  revalidate: number;
+}
+
+interface CachedRedirectValue {
+  kind: "REDIRECT";
+  props: Object;
+}
+
+interface CachedRouteValue {
+  kind: "ROUTE";
+  // this needs to be a RenderResult so since renderResponse
+  // expects that type instead of a string
+  body: Buffer;
+  status: number;
+  headers: Record<string, undefined | string | string[]>;
+}
+
+interface CachedImageValue {
+  kind: "IMAGE";
+  etag: string;
+  buffer: Buffer;
+  extension: string;
+  isMiss?: boolean;
+  isStale?: boolean;
+}
+
+interface IncrementalCachedPageValue {
+  kind: "PAGE";
+  // this needs to be a string since the cache expects to store
+  // the string value
+  html: string;
+  pageData: Object;
+  status?: number;
+  headers?: Record<string, undefined | string>;
+}
+
+type IncrementalCacheValue =
+  | CachedRedirectValue
+  | IncrementalCachedPageValue
+  | CachedImageValue
+  | CachedFetchValue
+  | CachedRouteValue;
+
+export interface CacheHandlerContext {
+  fs?: never;
+  dev?: boolean;
+  flushToDisk?: boolean;
+  serverDistDir?: string;
+  maxMemoryCacheSize?: number;
+  _appDir: boolean;
+  _requestHeaders: never;
+  fetchCacheKeyPrefix?: string;
+}
+
+export interface CacheHandlerValue {
+  lastModified?: number;
+  age?: number;
+  cacheState?: string;
+  value: IncrementalCacheValue | null;
+}
+
+export type Extension = "cache" | "fetch";
+
+export interface Meta {
+  status?: number;
+  headers?: Record<string, undefined | string | string[]>;
+}
diff --git a/packages/open-next/src/cache/tag/dynamoDb.ts b/packages/open-next/src/cache/tag/dynamoDb.ts
new file mode 100644
index 000000000..5cf76bb2c
--- /dev/null
+++ b/packages/open-next/src/cache/tag/dynamoDb.ts
@@ -0,0 +1,149 @@
+import {
+  BatchWriteItemCommand,
+  DynamoDBClient,
+  DynamoDBClientConfig,
+  QueryCommand,
+} from "@aws-sdk/client-dynamodb";
+import path from "path";
+
+import { MAX_DYNAMO_BATCH_WRITE_ITEM_COUNT } from "../../adapters/constants";
+import { awsLogger, debug, error } from "../../adapters/logger";
+import { chunk, parseNumberFromEnv } from "../../adapters/util";
+import { TagCache } from "./types";
+
+const { CACHE_BUCKET_REGION, CACHE_DYNAMO_TABLE, NEXT_BUILD_ID } = process.env;
+
+function parseDynamoClientConfigFromEnv(): DynamoDBClientConfig {
+  return {
+    region: CACHE_BUCKET_REGION,
+    logger: awsLogger,
+    maxAttempts: parseNumberFromEnv(process.env.AWS_SDK_DYNAMODB_MAX_ATTEMPTS),
+  };
+}
+
+const dynamoClient = new DynamoDBClient(parseDynamoClientConfigFromEnv());
+
+function buildDynamoKey(key: string) {
+  // FIXME: We should probably use something else than path.join here
+  // this could transform some fetch cache key into a valid path
+  return path.posix.join(NEXT_BUILD_ID ?? "", key);
+}
+
+function buildDynamoObject(path: string, tags: string, revalidatedAt?: number) {
+  return {
+    path: { S: buildDynamoKey(path) },
+    tag: { S: buildDynamoKey(tags) },
+    revalidatedAt: { N: `${revalidatedAt ?? Date.now()}` },
+  };
+}
+
+const tagCache: TagCache = {
+  async getByPath(path) {
+    try {
+      if (globalThis.disableDynamoDBCache) return [];
+      const result = await dynamoClient.send(
+        new QueryCommand({
+          TableName: CACHE_DYNAMO_TABLE,
+          IndexName: "revalidate",
+          KeyConditionExpression: "#key = :key",
+          ExpressionAttributeNames: {
+            "#key": "path",
+          },
+          ExpressionAttributeValues: {
+            ":key": { S: buildDynamoKey(path) },
+          },
+        }),
+      );
+      const tags = result.Items?.map((item) => item.tag.S ?? "") ?? [];
+      debug("tags for path", path, tags);
+      return tags;
+    } catch (e) {
+      error("Failed to get tags by path", e);
+      return [];
+    }
+  },
+  async getByTag(tag) {
+    try {
+      if (globalThis.disableDynamoDBCache) return [];
+      const { Items } = await dynamoClient.send(
+        new QueryCommand({
+          TableName: CACHE_DYNAMO_TABLE,
+          KeyConditionExpression: "#tag = :tag",
+          ExpressionAttributeNames: {
+            "#tag": "tag",
+          },
+          ExpressionAttributeValues: {
+            ":tag": { S: buildDynamoKey(tag) },
+          },
+        }),
+      );
+      return (
+        // We need to remove the buildId from the path
+        Items?.map(
+          ({ path: { S: key } }) => key?.replace(`${NEXT_BUILD_ID}/`, "") ?? "",
+        ) ?? []
+      );
+    } catch (e) {
+      error("Failed to get by tag", e);
+      return [];
+    }
+  },
+  async getLastModified(key, lastModified) {
+    try {
+      if (globalThis.disableDynamoDBCache) return lastModified ?? Date.now();
+      const result = await dynamoClient.send(
+        new QueryCommand({
+          TableName: CACHE_DYNAMO_TABLE,
+          IndexName: "revalidate",
+          KeyConditionExpression:
+            "#key = :key AND #revalidatedAt > :lastModified",
+          ExpressionAttributeNames: {
+            "#key": "path",
+            "#revalidatedAt": "revalidatedAt",
+          },
+          ExpressionAttributeValues: {
+            ":key": { S: buildDynamoKey(key) },
+            ":lastModified": { N: String(lastModified ?? 0) },
+          },
+        }),
+      );
+      const revalidatedTags = result.Items ?? [];
+      debug("revalidatedTags", revalidatedTags);
+      // If we have revalidated tags we return -1 to force revalidation
+      return revalidatedTags.length > 0 ? -1 : lastModified ?? Date.now();
+    } catch (e) {
+      error("Failed to get revalidated tags", e);
+      return lastModified ?? Date.now();
+    }
+  },
+  async writeTags(tags) {
+    try {
+      if (globalThis.disableDynamoDBCache) return;
+      await Promise.all(
+        chunk(tags, MAX_DYNAMO_BATCH_WRITE_ITEM_COUNT).map((Items) => {
+          return dynamoClient.send(
+            new BatchWriteItemCommand({
+              RequestItems: {
+                [CACHE_DYNAMO_TABLE ?? ""]: Items.map((Item) => ({
+                  PutRequest: {
+                    Item: {
+                      ...buildDynamoObject(
+                        Item.path,
+                        Item.tag,
+                        Item.revalidatedAt,
+                      ),
+                    },
+                  },
+                })),
+              },
+            }),
+          );
+        }),
+      );
+    } catch (e) {
+      error("Failed to batch write dynamo item", e);
+    }
+  },
+};
+
+export default tagCache;
diff --git a/packages/open-next/src/cache/tag/types.ts b/packages/open-next/src/cache/tag/types.ts
new file mode 100644
index 000000000..eb4643787
--- /dev/null
+++ b/packages/open-next/src/cache/tag/types.ts
@@ -0,0 +1,8 @@
+export type TagCache = {
+  getByTag(tag: string): Promise<string[]>;
+  getByPath(path: string): Promise<string[]>;
+  getLastModified(path: string, lastModified?: number): Promise<number>;
+  writeTags(
+    tags: { tag: string; path: string; revalidatedAt?: number }[],
+  ): Promise<void>;
+};
diff --git a/packages/open-next/src/converters/aws-apigw-v1.ts b/packages/open-next/src/converters/aws-apigw-v1.ts
new file mode 100644
index 000000000..7750fc457
--- /dev/null
+++ b/packages/open-next/src/converters/aws-apigw-v1.ts
@@ -0,0 +1,108 @@
+import { APIGatewayProxyEvent, APIGatewayProxyResult } from "aws-lambda";
+import type { Converter, InternalEvent, InternalResult } from "types/open-next";
+
+import { debug } from "../adapters/logger";
+import { removeUndefinedFromQuery } from "./utils";
+
+function normalizeAPIGatewayProxyEventHeaders(
+  event: APIGatewayProxyEvent,
+): Record<string, string> {
+  event.multiValueHeaders;
+  const headers: Record<string, string> = {};
+
+  for (const [key, values] of Object.entries(event.multiValueHeaders || {})) {
+    if (values) {
+      headers[key.toLowerCase()] = values.join(",");
+    }
+  }
+  for (const [key, value] of Object.entries(event.headers || {})) {
+    if (value) {
+      headers[key.toLowerCase()] = value;
+    }
+  }
+  return headers;
+}
+
+function normalizeAPIGatewayProxyEventQueryParams(
+  event: APIGatewayProxyEvent,
+): string {
+  // Note that the same query string values are returned in both
+  // "multiValueQueryStringParameters" and "queryStringParameters".
+  // We only need to use one of them.
+  // For example:
+  //   "?name=foo" appears in the event object as
+  //   {
+  //     ...
+  //     queryStringParameters: { name: 'foo' },
+  //     multiValueQueryStringParameters: { name: [ 'foo' ] },
+  //     ...
+  //   }
+  const params = new URLSearchParams();
+  for (const [key, value] of Object.entries(
+    event.multiValueQueryStringParameters || {},
+  )) {
+    if (value !== undefined) {
+      for (const v of value) {
+        params.append(key, v);
+      }
+    }
+  }
+  const value = params.toString();
+  return value ? `?${value}` : "";
+}
+
+async function convertFromAPIGatewayProxyEvent(
+  event: APIGatewayProxyEvent,
+): Promise<InternalEvent> {
+  const { path, body, httpMethod, requestContext, isBase64Encoded } = event;
+  return {
+    type: "core",
+    method: httpMethod,
+    rawPath: path,
+    url: path + normalizeAPIGatewayProxyEventQueryParams(event),
+    body: Buffer.from(body ?? "", isBase64Encoded ? "base64" : "utf8"),
+    headers: normalizeAPIGatewayProxyEventHeaders(event),
+    remoteAddress: requestContext.identity.sourceIp,
+    query: removeUndefinedFromQuery(
+      event.multiValueQueryStringParameters ?? {},
+    ),
+    cookies:
+      event.multiValueHeaders?.cookie?.reduce((acc, cur) => {
+        const [key, value] = cur.split("=");
+        return { ...acc, [key]: value };
+      }, {}) ?? {},
+  };
+}
+
+function convertToApiGatewayProxyResult(
+  result: InternalResult,
+): APIGatewayProxyResult {
+  const headers: Record<string, string> = {};
+  const multiValueHeaders: Record<string, string[]> = {};
+  Object.entries(result.headers).forEach(([key, value]) => {
+    if (Array.isArray(value)) {
+      multiValueHeaders[key] = value;
+    } else {
+      if (value === null) {
+        headers[key] = "";
+        return;
+      }
+      headers[key] = value;
+    }
+  });
+
+  const response: APIGatewayProxyResult = {
+    statusCode: result.statusCode,
+    headers,
+    body: result.body,
+    isBase64Encoded: result.isBase64Encoded,
+    multiValueHeaders,
+  };
+  debug(response);
+  return response;
+}
+
+export default {
+  convertFrom: convertFromAPIGatewayProxyEvent,
+  convertTo: convertToApiGatewayProxyResult,
+} as Converter;
diff --git a/packages/open-next/src/converters/aws-apigw-v2.ts b/packages/open-next/src/converters/aws-apigw-v2.ts
new file mode 100644
index 000000000..f91ead82c
--- /dev/null
+++ b/packages/open-next/src/converters/aws-apigw-v2.ts
@@ -0,0 +1,90 @@
+import { APIGatewayProxyEventV2, APIGatewayProxyResultV2 } from "aws-lambda";
+import { parseCookies } from "http/util";
+import type { Converter, InternalEvent, InternalResult } from "types/open-next";
+
+import { debug } from "../adapters/logger";
+import { removeUndefinedFromQuery } from "./utils";
+
+function normalizeAPIGatewayProxyEventV2Body(
+  event: APIGatewayProxyEventV2,
+): Buffer {
+  const { body, isBase64Encoded } = event;
+  if (Buffer.isBuffer(body)) {
+    return body;
+  } else if (typeof body === "string") {
+    return Buffer.from(body, isBase64Encoded ? "base64" : "utf8");
+  } else if (typeof body === "object") {
+    return Buffer.from(JSON.stringify(body));
+  } else {
+    return Buffer.from("", "utf8");
+  }
+}
+
+function normalizeAPIGatewayProxyEventV2Headers(
+  event: APIGatewayProxyEventV2,
+): Record<string, string> {
+  const { headers: rawHeaders, cookies } = event;
+
+  const headers: Record<string, string> = {};
+
+  if (Array.isArray(cookies)) {
+    headers["cookie"] = cookies.join("; ");
+  }
+
+  for (const [key, value] of Object.entries(rawHeaders || {})) {
+    headers[key.toLowerCase()] = value!;
+  }
+
+  return headers;
+}
+
+async function convertFromAPIGatewayProxyEventV2(
+  event: APIGatewayProxyEventV2,
+): Promise<InternalEvent> {
+  const { rawPath, rawQueryString, requestContext } = event;
+  return {
+    type: "core",
+    method: requestContext.http.method,
+    rawPath,
+    url: rawPath + (rawQueryString ? `?${rawQueryString}` : ""),
+    body: normalizeAPIGatewayProxyEventV2Body(event),
+    headers: normalizeAPIGatewayProxyEventV2Headers(event),
+    remoteAddress: requestContext.http.sourceIp,
+    query: removeUndefinedFromQuery(event.queryStringParameters ?? {}),
+    cookies:
+      event.cookies?.reduce((acc, cur) => {
+        const [key, value] = cur.split("=");
+        return { ...acc, [key]: value };
+      }, {}) ?? {},
+  };
+}
+
+function convertToApiGatewayProxyResultV2(
+  result: InternalResult,
+): APIGatewayProxyResultV2 {
+  const headers: Record<string, string> = {};
+  Object.entries(result.headers)
+    .filter(([key]) => key.toLowerCase() !== "set-cookie")
+    .forEach(([key, value]) => {
+      if (value === null) {
+        headers[key] = "";
+        return;
+      }
+      headers[key] = Array.isArray(value) ? value.join(", ") : value.toString();
+    });
+
+  const response: APIGatewayProxyResultV2 = {
+    statusCode: result.statusCode,
+    headers,
+    cookies: parseCookies(result.headers["set-cookie"]),
+    body: result.body,
+    isBase64Encoded: result.isBase64Encoded,
+  };
+  debug(response);
+  return response;
+}
+
+export default {
+  convertFrom: convertFromAPIGatewayProxyEventV2,
+  convertTo: convertToApiGatewayProxyResultV2,
+} as Converter;
diff --git a/packages/open-next/src/converters/aws-cloudfront.ts b/packages/open-next/src/converters/aws-cloudfront.ts
new file mode 100644
index 000000000..7b72b9bab
--- /dev/null
+++ b/packages/open-next/src/converters/aws-cloudfront.ts
@@ -0,0 +1,86 @@
+import {
+  CloudFrontHeaders,
+  CloudFrontRequestEvent,
+  CloudFrontRequestResult,
+} from "aws-lambda";
+import type { Converter, InternalEvent, InternalResult } from "types/open-next";
+
+import { debug } from "../adapters/logger";
+
+function normalizeCloudFrontRequestEventHeaders(
+  rawHeaders: CloudFrontHeaders,
+): Record<string, string> {
+  const headers: Record<string, string> = {};
+
+  for (const [key, values] of Object.entries(rawHeaders)) {
+    for (const { value } of values) {
+      if (value) {
+        headers[key.toLowerCase()] = value;
+      }
+    }
+  }
+
+  return headers;
+}
+
+async function convertFromCloudFrontRequestEvent(
+  event: CloudFrontRequestEvent,
+): Promise<InternalEvent> {
+  const { method, uri, querystring, body, headers, clientIp } =
+    event.Records[0].cf.request;
+  return {
+    type: "core",
+    method,
+    rawPath: uri,
+    url: uri + (querystring ? `?${querystring}` : ""),
+    body: Buffer.from(
+      body?.data ?? "",
+      body?.encoding === "base64" ? "base64" : "utf8",
+    ),
+    headers: normalizeCloudFrontRequestEventHeaders(headers),
+    remoteAddress: clientIp,
+    query: querystring.split("&").reduce(
+      (acc, cur) => ({
+        ...acc,
+        [cur.split("=")[0]]: cur.split("=")[1],
+      }),
+      {},
+    ),
+    cookies:
+      headers.cookie?.reduce((acc, cur) => {
+        const { key, value } = cur;
+        return { ...acc, [key ?? ""]: value };
+      }, {}) ?? {},
+  };
+}
+
+function convertToCloudFrontRequestResult(
+  result: InternalResult,
+): CloudFrontRequestResult {
+  const headers: CloudFrontHeaders = {};
+  Object.entries(result.headers)
+    .filter(([key]) => key.toLowerCase() !== "content-length")
+    .forEach(([key, value]) => {
+      headers[key] = [
+        ...(headers[key] || []),
+        ...(Array.isArray(value)
+          ? value.map((v) => ({ key, value: v }))
+          : [{ key, value: value.toString() }]),
+      ];
+    });
+
+  const response: CloudFrontRequestResult = {
+    status: result.statusCode.toString(),
+    statusDescription: "OK",
+    headers,
+    bodyEncoding: result.isBase64Encoded ? "base64" : "text",
+    body: result.body,
+  };
+  debug(response);
+  return response;
+}
+
+export default {
+  convertFrom: convertFromCloudFrontRequestEvent,
+  convertTo: convertToCloudFrontRequestResult,
+} as Converter;
diff --git a/packages/open-next/src/converters/dummy.ts b/packages/open-next/src/converters/dummy.ts
new file mode 100644
index 000000000..c1bc833b1
--- /dev/null
+++ b/packages/open-next/src/converters/dummy.ts
@@ -0,0 +1,23 @@
+import { Converter } from "types/open-next";
+
+type DummyEventOrResult = {
+  type: "dummy";
+  original: any;
+};
+
+const converter: Converter<DummyEventOrResult, DummyEventOrResult> = {
+  convertFrom(event) {
+    return Promise.resolve({
+      type: "dummy",
+      original: event,
+    });
+  },
+  convertTo(internalResult) {
+    return Promise.resolve({
+      type: "dummy",
+      original: internalResult,
+    });
+  },
+};
+
+export default converter;
diff --git a/packages/open-next/src/converters/edge.ts b/packages/open-next/src/converters/edge.ts
new file mode 100644
index 000000000..bad375747
--- /dev/null
+++ b/packages/open-next/src/converters/edge.ts
@@ -0,0 +1,73 @@
+import { parseCookies } from "http/util";
+import { Converter, InternalEvent, InternalResult } from "types/open-next";
+
+import { MiddlewareOutputEvent } from "../core/routingHandler";
+
+const converter: Converter<
+  InternalEvent,
+  InternalResult | ({ type: "middleware" } & MiddlewareOutputEvent)
+> = {
+  convertFrom: async (event: Request) => {
+    const searchParams = new URL(event.url).searchParams;
+    const query: Record<string, string | string[]> = {};
+    for (const [key, value] of searchParams.entries()) {
+      if (query[key]) {
+        if (Array.isArray(query[key])) {
+          (query[key] as string[]).push(value);
+        } else {
+          query[key] = [query[key] as string, value];
+        }
+      } else {
+        query[key] = value;
+      }
+    }
+    //Transform body into Buffer
+    const body = await event.arrayBuffer();
+    const headers: Record<string, string> = {};
+    event.headers.forEach((value, key) => {
+      headers[key] = value;
+    });
+    const rawPath = new URL(event.url).pathname;
+
+    return {
+      type: "core",
+      method: event.method,
+      rawPath,
+      url: event.url,
+      body: event.method !== "GET" ? Buffer.from(body) : undefined,
+      headers: headers,
+      remoteAddress: (event.headers.get("x-forwarded-for") as string) ?? "::1",
+      query,
+      cookies: Object.fromEntries(
+        parseCookies(event.headers.get("cookie") ?? "")?.map((cookie) => {
+          const [key, value] = cookie.split("=");
+          return [key, value];
+        }) ?? [],
+      ),
+    };
+  },
+  convertTo: async (result) => {
+    if ("internalEvent" in result) {
+      const url = result.isExternalRewrite
+        ? result.internalEvent.url
+        : `https://${result.internalEvent.headers.host}${result.internalEvent.url}`;
+      const req = new Request(url, {
+        body: result.internalEvent.body,
+        method: result.internalEvent.method,
+        headers: result.internalEvent.headers,
+      });
+      return fetch(req);
+    } else {
+      const headers = new Headers();
+      for (const [key, value] of Object.entries(result.headers)) {
+        headers.set(key, Array.isArray(value) ? value.join(",") : value);
+      }
+      return new Response(result.body, {
+        status: result.statusCode,
+        headers: headers,
+      });
+    }
+  },
+};
+
+export default converter;
diff --git a/packages/open-next/src/converters/node.ts b/packages/open-next/src/converters/node.ts
new file mode 100644
index 000000000..112bef7c4
--- /dev/null
+++ b/packages/open-next/src/converters/node.ts
@@ -0,0 +1,54 @@
+import { IncomingMessage } from "http";
+import { parseCookies } from "http/util";
+import type { Converter, InternalResult } from "types/open-next";
+
+const converter: Converter = {
+  convertFrom: async (req: IncomingMessage) => {
+    const body = await new Promise<Buffer>((resolve) => {
+      const chunks: Uint8Array[] = [];
+      req.on("data", (chunk) => {
+        chunks.push(chunk);
+      });
+      req.on("end", () => {
+        resolve(Buffer.concat(chunks));
+      });
+    });
+
+    const url = new URL(req.url!, `http://${req.headers.host}`);
+    const query = Object.fromEntries(url.searchParams.entries());
+    return {
+      type: "core",
+      method: req.method ?? "GET",
+      rawPath: url.pathname,
+      url: url.toString(),
+      body,
+      headers: Object.fromEntries(
+        Object.entries(req.headers ?? {})
+          .map(([key, value]) => [
+            key.toLowerCase(),
+            Array.isArray(value) ? value.join(",") : value,
+          ])
+          .filter(([key]) => key),
+      ),
+      remoteAddress:
+        (req.headers["x-forwarded-for"] as string) ??
+        req.socket.remoteAddress ??
+        "::1",
+      query,
+      cookies: Object.fromEntries(
+        parseCookies(req.headers["cookie"])?.map((cookie) => {
+          const [key, value] = cookie.split("=");
+          return [key, value];
+        }) ?? [],
+      ),
+    };
+  },
+  // Nothing to do here, it's streaming
+  convertTo: (internalResult: InternalResult) => ({
+    body: internalResult.body,
+    headers: internalResult.headers,
+    statusCode: internalResult.statusCode,
+  }),
+};
+
+export default converter;
diff --git a/packages/open-next/src/converters/sqs-revalidate.ts b/packages/open-next/src/converters/sqs-revalidate.ts
new file mode 100644
index 000000000..d701782ce
--- /dev/null
+++ b/packages/open-next/src/converters/sqs-revalidate.ts
@@ -0,0 +1,24 @@
+import { SQSEvent } from "aws-lambda";
+import { Converter } from "types/open-next";
+
+import { RevalidateEvent } from "../adapters/revalidate";
+
+const converter: Converter<RevalidateEvent, { type: "revalidate" }> = {
+  convertFrom(event: SQSEvent) {
+    const records = event.Records.map((record) => {
+      const { host, url } = JSON.parse(record.body);
+      return { host, url };
+    });
+    return Promise.resolve({
+      type: "revalidate",
+      records,
+    });
+  },
+  convertTo() {
+    return Promise.resolve({
+      type: "revalidate",
+    });
+  },
+};
+
+export default converter;
diff --git a/packages/open-next/src/converters/utils.ts b/packages/open-next/src/converters/utils.ts
new file mode 100644
index 000000000..13b7e8102
--- /dev/null
+++ b/packages/open-next/src/converters/utils.ts
@@ -0,0 +1,11 @@
+export function removeUndefinedFromQuery(
+  query: Record<string, string | string[] | undefined>,
+) {
+  const newQuery: Record<string, string | string[]> = {};
+  for (const [key, value] of Object.entries(query)) {
+    if (value !== undefined) {
+      newQuery[key] = value;
+    }
+  }
+  return newQuery;
+}
diff --git a/packages/open-next/src/core/createGenericHandler.ts b/packages/open-next/src/core/createGenericHandler.ts
new file mode 100644
index 000000000..aef5e67ef
--- /dev/null
+++ b/packages/open-next/src/core/createGenericHandler.ts
@@ -0,0 +1,56 @@
+import type {
+  BaseEventOrResult,
+  BuildOptions,
+  DefaultOverrideOptions,
+  InternalEvent,
+  InternalResult,
+  OpenNextHandler,
+} from "types/open-next";
+
+import { resolveConverter, resolveWrapper } from "./resolve";
+
+declare global {
+  var openNextConfig: Partial<BuildOptions>;
+}
+
+type HandlerType =
+  | "imageOptimization"
+  | "revalidate"
+  | "warmer"
+  | "middleware"
+  | "initializationFunction";
+
+type GenericHandler<
+  Type extends HandlerType,
+  E extends BaseEventOrResult = InternalEvent,
+  R extends BaseEventOrResult = InternalResult,
+> = {
+  handler: OpenNextHandler<E, R>;
+  type: Type;
+};
+
+export async function createGenericHandler<
+  Type extends HandlerType,
+  E extends BaseEventOrResult = InternalEvent,
+  R extends BaseEventOrResult = InternalResult,
+>(handler: GenericHandler<Type, E, R>) {
+  //First we load the config
+  //@ts-expect-error
+  const config: BuildOptions = await import("./open-next.config.js").then(
+    (m) => m.default,
+  );
+
+  globalThis.openNextConfig = {
+    [handler.type]: config[handler.type],
+  };
+  const override = config[handler.type]
+    ?.override as any as DefaultOverrideOptions<E, R>;
+
+  // From the config, we create the adapter
+  const adapter = await resolveConverter<E, R>(override?.converter);
+
+  // Then we create the handler
+  const wrapper = await resolveWrapper<E, R>(override?.wrapper);
+
+  return wrapper(handler.handler, adapter);
+}
diff --git a/packages/open-next/src/core/createMainHandler.ts b/packages/open-next/src/core/createMainHandler.ts
new file mode 100644
index 000000000..649ec8edf
--- /dev/null
+++ b/packages/open-next/src/core/createMainHandler.ts
@@ -0,0 +1,63 @@
+import type { BuildOptions, OverrideOptions } from "types/open-next";
+
+import type { IncrementalCache } from "../cache/incremental/types";
+import type { Queue } from "../queue/types";
+import { openNextHandler } from "./requestHandler";
+import { resolveConverter, resolveTagCache, resolveWrapper } from "./resolve";
+
+declare global {
+  var queue: Queue;
+  var incrementalCache: IncrementalCache;
+}
+
+async function resolveQueue(queue: OverrideOptions["queue"]) {
+  if (typeof queue === "string") {
+    const m = await import(`../queue/${queue}.js`);
+    return m.default;
+  } else if (typeof queue === "function") {
+    return queue();
+  } else {
+    const m_1 = await import("../queue/sqs.js");
+    return m_1.default;
+  }
+}
+
+async function resolveIncrementalCache(
+  incrementalCache: OverrideOptions["incrementalCache"],
+) {
+  if (typeof incrementalCache === "string") {
+    const m = await import(`../cache/incremental/${incrementalCache}.js`);
+    return m.default;
+  } else if (typeof incrementalCache === "function") {
+    return incrementalCache();
+  } else {
+    const m_1 = await import("../cache/incremental/s3.js");
+    return m_1.default;
+  }
+}
+
+export async function createMainHandler() {
+  //First we load the config
+  const config: BuildOptions = await import(
+    process.cwd() + "/open-next.config.js"
+  ).then((m) => m.default);
+
+  const thisFunction = config.functions.default;
+
+  // Default queue
+  globalThis.queue = await resolveQueue(thisFunction.override?.queue);
+
+  globalThis.incrementalCache = await resolveIncrementalCache(
+    thisFunction.override?.incrementalCache,
+  );
+
+  globalThis.tagCache = await resolveTagCache(thisFunction.override?.tagCache);
+
+  // From the config, we create the adapter
+  const adapter = await resolveConverter(thisFunction.override?.converter);
+
+  // Then we create the handler
+  const wrapper = await resolveWrapper(thisFunction.override?.wrapper);
+
+  return wrapper(openNextHandler, adapter);
+}
diff --git a/packages/open-next/src/core/edgeFunctionHandler.ts b/packages/open-next/src/core/edgeFunctionHandler.ts
new file mode 100644
index 000000000..4a5962f4d
--- /dev/null
+++ b/packages/open-next/src/core/edgeFunctionHandler.ts
@@ -0,0 +1,110 @@
+// Necessary files will be imported here with banner in esbuild
+
+import type { OutgoingHttpHeaders } from "http";
+
+interface RequestData {
+  geo?: {
+    city?: string;
+    country?: string;
+    region?: string;
+    latitude?: string;
+    longitude?: string;
+  };
+  headers: OutgoingHttpHeaders;
+  ip?: string;
+  method: string;
+  nextConfig?: {
+    basePath?: string;
+    i18n?: any;
+    trailingSlash?: boolean;
+  };
+  page?: {
+    name?: string;
+    params?: { [key: string]: string | string[] };
+  };
+  url: string;
+  body?: ReadableStream<Uint8Array>;
+  signal: AbortSignal;
+}
+
+interface Entries {
+  [k: string]: {
+    default: (props: { page: string; request: RequestData }) => Promise<{
+      response: Response;
+      waitUntil: Promise<void>;
+    }>;
+  };
+}
+declare global {
+  var _ENTRIES: Entries;
+  var __storage__: Map<unknown, unknown>;
+  var AsyncContext: any;
+  //@ts-ignore
+  var AsyncLocalStorage: any;
+}
+
+interface Route {
+  name: string;
+  page: string;
+  regex: string;
+}
+
+export default async function edgeFunctionHandler(
+  routes: Route[],
+  request: RequestData,
+): Promise<Response> {
+  const path = new URL(request.url).pathname;
+  const correspondingRoute = routes.find((route) =>
+    new RegExp(route.regex).test(path),
+  );
+
+  if (!correspondingRoute) {
+    throw new Error(`No route found for ${request.url}`);
+  }
+
+  const result = await self._ENTRIES[
+    `middleware_${correspondingRoute.name}`
+  ].default({
+    page: correspondingRoute.page,
+    request: {
+      headers: request.headers,
+      method: request.method,
+      url: request.url,
+      signal: request.signal,
+      page: {
+        name: correspondingRoute.name,
+      },
+    },
+  });
+  await result.waitUntil;
+  const response = result.response;
+  return response;
+}
+
+// const route = "/ssr/page";
+
+// const toExport = {
+//   async fetch(req: Request, env: any, context: any) {
+//     const headers: Record<string, string> = {};
+//     req.headers.forEach((value, key) => {
+//       headers[key] = value;
+//     });
+//     const result = await self._ENTRIES[`middleware_app${route}`].default({
+//       page: route,
+//       request: {
+//         headers: headers,
+//         method: req.method,
+//         url: req.url,
+//         signal: req.signal,
+//         page: {
+//           name: route,
+//         },
+//       },
+//     });
+//     const response = result.response;
+//     context.waitUntil(result.waitUntil);
+//     return response;
+//   },
+// };
+
+// export default toExport;
diff --git a/packages/open-next/src/core/requestHandler.ts b/packages/open-next/src/core/requestHandler.ts
new file mode 100644
index 000000000..1c2c7695b
--- /dev/null
+++ b/packages/open-next/src/core/requestHandler.ts
@@ -0,0 +1,120 @@
+import {
+  IncomingMessage,
+  OpenNextNodeResponse,
+  StreamCreator,
+} from "http/index.js";
+import { InternalEvent, InternalResult } from "types/open-next";
+
+import { debug, error } from "../adapters/logger";
+import { convertRes, createServerResponse, proxyRequest } from "./routing/util";
+import routingHandler from "./routingHandler";
+import { requestHandler, setNextjsPrebundledReact } from "./util";
+
+export async function openNextHandler(
+  internalEvent: InternalEvent,
+  responseStreaming?: StreamCreator,
+): Promise<InternalResult> {
+  if (internalEvent.headers["x-forwarded-host"]) {
+    internalEvent.headers.host = internalEvent.headers["x-forwarded-host"];
+  }
+  debug("internalEvent", internalEvent);
+
+  //#override withRouting
+  const preprocessResult = await routingHandler(internalEvent);
+  //#endOverride
+
+  if ("type" in preprocessResult) {
+    // res is used only in the streaming case
+    const headers = preprocessResult.headers;
+    const res = createServerResponse(internalEvent, headers, responseStreaming);
+    res.statusCode = preprocessResult.statusCode;
+    res.flushHeaders();
+    res.write(preprocessResult.body);
+    res.end();
+    return preprocessResult;
+  } else {
+    const preprocessedEvent = preprocessResult.internalEvent;
+    debug("preprocessedEvent", preprocessedEvent);
+    const reqProps = {
+      method: preprocessedEvent.method,
+      url: preprocessedEvent.url,
+      //WORKAROUND: We pass this header to the serverless function to mimic a prefetch request which will not trigger revalidation since we handle revalidation differently
+      // There is 3 way we can handle revalidation:
+      // 1. We could just let the revalidation go as normal, but due to race condtions the revalidation will be unreliable
+      // 2. We could alter the lastModified time of our cache to make next believe that the cache is fresh, but this could cause issues with stale data since the cdn will cache the stale data as if it was fresh
+      // 3. OUR CHOICE: We could pass a purpose prefetch header to the serverless function to make next believe that the request is a prefetch request and not trigger revalidation (This could potentially break in the future if next changes the behavior of prefetch requests)
+      headers: { ...preprocessedEvent.headers, purpose: "prefetch" },
+      body: preprocessedEvent.body,
+      remoteAddress: preprocessedEvent.remoteAddress,
+    };
+    const req = new IncomingMessage(reqProps);
+    const res = createServerResponse(
+      preprocessedEvent,
+      preprocessResult.headers as Record<string, string | string[]>,
+      responseStreaming,
+    );
+
+    await processRequest(
+      req,
+      res,
+      preprocessedEvent,
+      preprocessResult.isExternalRewrite,
+    );
+
+    const { statusCode, headers, isBase64Encoded, body } = convertRes(res);
+
+    const internalResult = {
+      type: internalEvent.type,
+      statusCode,
+      headers,
+      body,
+      isBase64Encoded,
+    };
+
+    return internalResult;
+  }
+}
+
+async function processRequest(
+  req: IncomingMessage,
+  res: OpenNextNodeResponse,
+  internalEvent: InternalEvent,
+  isExternalRewrite?: boolean,
+) {
+  // @ts-ignore
+  // Next.js doesn't parse body if the property exists
+  // https://github.com/dougmoscrop/serverless-http/issues/227
+  delete req.body;
+
+  try {
+    // `serverHandler` is replaced at build time depending on user's
+    // nextjs version to patch Nextjs 13.4.x and future breaking changes.
+
+    const { rawPath } = internalEvent;
+
+    if (isExternalRewrite) {
+      return proxyRequest(internalEvent, res);
+    } else {
+      //#override applyNextjsPrebundledReact
+      setNextjsPrebundledReact(rawPath);
+      //#endOverride
+
+      // Next Server
+      await requestHandler(req, res);
+    }
+  } catch (e: any) {
+    error("NextJS request failed.", e);
+    //TODO: we could return the next 500 page here
+    res.setHeader("Content-Type", "application/json");
+    res.end(
+      JSON.stringify(
+        {
+          message: "Server failed to respond.",
+          details: e,
+        },
+        null,
+        2,
+      ),
+    );
+  }
+}
diff --git a/packages/open-next/src/adapters/require-hooks.ts b/packages/open-next/src/core/require-hooks.ts
similarity index 98%
rename from packages/open-next/src/adapters/require-hooks.ts
rename to packages/open-next/src/core/require-hooks.ts
index 255fe2f0f..963dbfa96 100644
--- a/packages/open-next/src/adapters/require-hooks.ts
+++ b/packages/open-next/src/core/require-hooks.ts
@@ -2,8 +2,9 @@
 // This is needed for userland plugins to attach to the same webpack instance as Next.js'.
 // Individually compiled modules are as defined for the compilation in bundles/webpack/packages/*.
 
-import { error } from "./logger.js";
-import type { NextConfig } from "./types/next-types.js";
+import type { NextConfig } from "types/next-types.js";
+
+import { error } from "../adapters/logger.js";
 
 // This module will only be loaded once per process.
 
diff --git a/packages/open-next/src/core/resolve.ts b/packages/open-next/src/core/resolve.ts
new file mode 100644
index 000000000..918d85d6c
--- /dev/null
+++ b/packages/open-next/src/core/resolve.ts
@@ -0,0 +1,58 @@
+import {
+  BaseEventOrResult,
+  Converter,
+  DefaultOverrideOptions,
+  InternalEvent,
+  InternalResult,
+  OverrideOptions,
+  Wrapper,
+} from "types/open-next.js";
+
+import { TagCache } from "../cache/tag/types.js";
+
+export async function resolveConverter<
+  E extends BaseEventOrResult = InternalEvent,
+  R extends BaseEventOrResult = InternalResult,
+>(
+  converter: DefaultOverrideOptions<E, R>["converter"],
+): Promise<Converter<E, R>> {
+  if (typeof converter === "function") {
+    return converter();
+  } else {
+    const m_1 = await import(`../converters/aws-apigw-v2.js`);
+    // @ts-expect-error
+    return m_1.default;
+  }
+}
+
+export async function resolveWrapper<
+  E extends BaseEventOrResult = InternalEvent,
+  R extends BaseEventOrResult = InternalResult,
+>(wrapper: DefaultOverrideOptions<E, R>["wrapper"]): Promise<Wrapper<E, R>> {
+  if (typeof wrapper === "function") {
+    return wrapper();
+  } else {
+    // This will be replaced by the bundler
+    const m_1 = await import("../wrappers/aws-lambda.js");
+    // @ts-expect-error
+    return m_1.default;
+  }
+}
+
+/**
+ *
+ * @param tagCache
+ * @returns
+ * @__PURE__
+ */
+export async function resolveTagCache(
+  tagCache: OverrideOptions["tagCache"],
+): Promise<TagCache> {
+  if (typeof tagCache === "function") {
+    return tagCache();
+  } else {
+    // This will be replaced by the bundler
+    const m_1 = await import("../cache/tag/dynamoDb.js");
+    return m_1.default;
+  }
+}
diff --git a/packages/open-next/src/adapters/routing/matcher.ts b/packages/open-next/src/core/routing/matcher.ts
similarity index 96%
rename from packages/open-next/src/adapters/routing/matcher.ts
rename to packages/open-next/src/core/routing/matcher.ts
index 4ac1a56b7..41da33e73 100644
--- a/packages/open-next/src/adapters/routing/matcher.ts
+++ b/packages/open-next/src/core/routing/matcher.ts
@@ -1,17 +1,22 @@
+import { NextConfig } from "config/index";
 import { compile, Match, match, PathFunction } from "path-to-regexp";
-
-import { NextConfig } from "../config";
-import { InternalEvent, InternalResult } from "../event-mapper";
-import { debug } from "../logger";
-import {
+import type {
   Header,
   PrerenderManifest,
   RedirectDefinition,
   RewriteDefinition,
   RouteHas,
-} from "../types/next-types";
-import { escapeRegex, unescapeRegex } from "../util";
-import { convertQuery, getUrlParts, isExternal } from "./util";
+} from "types/next-types";
+import { InternalEvent, InternalResult } from "types/open-next";
+
+import { debug } from "../../adapters/logger";
+import {
+  convertQuery,
+  escapeRegex,
+  getUrlParts,
+  isExternal,
+  unescapeRegex,
+} from "./util";
 
 const routeHasMatcher =
   (
diff --git a/packages/open-next/src/adapters/routing/middleware.ts b/packages/open-next/src/core/routing/middleware.ts
similarity index 64%
rename from packages/open-next/src/adapters/routing/middleware.ts
rename to packages/open-next/src/core/routing/middleware.ts
index f4de51548..89c7cd728 100644
--- a/packages/open-next/src/adapters/routing/middleware.ts
+++ b/packages/open-next/src/core/routing/middleware.ts
@@ -1,25 +1,16 @@
-import path from "node:path";
-
-import { NEXT_DIR, NextConfig } from "../config/index.js";
-import { InternalEvent, InternalResult } from "../event-mapper.js";
-import { IncomingMessage } from "../http/request.js";
-import { ServerlessResponse } from "../http/response.js";
-import {
-  convertRes,
-  getMiddlewareMatch,
-  isExternal,
-  loadMiddlewareManifest,
-} from "./util.js";
-
-const middlewareManifest = loadMiddlewareManifest(NEXT_DIR);
+import { MiddlewareManifest, NextConfig } from "config/index.js";
+import { InternalEvent, InternalResult } from "types/open-next.js";
 
 //NOTE: we should try to avoid importing stuff from next as much as possible
 // every release of next could break this
-const { run } = require("next/dist/server/web/sandbox");
-const { getCloneableBody } = require("next/dist/server/body-streams");
-const {
-  signalFromNodeResponse,
-} = require("next/dist/server/web/spec-extension/adapters/next-request");
+// const { run } = require("next/dist/server/web/sandbox");
+// const { getCloneableBody } = require("next/dist/server/body-streams");
+// const {
+//   signalFromNodeResponse,
+// } = require("next/dist/server/web/spec-extension/adapters/next-request");
+import { getMiddlewareMatch, isExternal } from "./util.js";
+
+const middlewareManifest = MiddlewareManifest;
 
 const middleMatch = getMiddlewareMatch(middlewareManifest);
 
@@ -33,10 +24,6 @@ type MiddlewareOutputEvent = InternalEvent & {
 // and res.body prior to processing the next-server.
 // @returns undefined | res.end()
 
-interface MiddlewareResult {
-  response: Response;
-}
-
 //    if res.end() is return, the parent needs to return and not process next server
 export async function handleMiddleware(
   internalEvent: InternalEvent,
@@ -47,19 +34,16 @@ export async function handleMiddleware(
   // We bypass the middleware if the request is internal
   if (internalEvent.headers["x-isr"]) return internalEvent;
 
-  const req = new IncomingMessage(internalEvent);
-  const res = new ServerlessResponse({
-    method: req.method ?? "GET",
-    headers: {},
-  });
+  // const req = new IncomingMessage(internalEvent);
+  // const res = new OpenNextNodeResponse(
+  //   () => void 0,
+  //   () => Promise.resolve(),
+  // );
 
   // NOTE: Next middleware was originally developed to support nested middlewares
   // but that was discarded for simplicity. The MiddlewareInfo type still has the original
   // structure, but as of now, the only useful property on it is the "/" key (ie root).
   const middlewareInfo = middlewareManifest.middleware["/"];
-  middlewareInfo.paths = middlewareInfo.files.map((file) =>
-    path.join(NEXT_DIR, file),
-  );
 
   const urlQuery: Record<string, string> = {};
   Object.keys(query).forEach((k) => {
@@ -67,34 +51,47 @@ export async function handleMiddleware(
     urlQuery[k] = Array.isArray(v) ? v.join(",") : v;
   });
 
-  const host = req.headers.host
-    ? `https://${req.headers.host}`
+  const host = internalEvent.headers.host
+    ? `https://${internalEvent.headers.host}`
     : "http://localhost:3000";
   const initialUrl = new URL(rawPath, host);
   initialUrl.search = new URLSearchParams(urlQuery).toString();
   const url = initialUrl.toString();
 
-  const result: MiddlewareResult = await run({
-    distDir: NEXT_DIR,
-    name: middlewareInfo.name || "/",
-    paths: middlewareInfo.paths || [],
-    edgeFunctionEntry: middlewareInfo,
-    request: {
-      headers: req.headers,
-      method: req.method || "GET",
+  const convertBodyToReadableStream = (body: string | Buffer) => {
+    const readable = new ReadableStream({
+      start(controller) {
+        controller.enqueue(body);
+        controller.close();
+      },
+    });
+    return readable;
+  };
+
+  // @ts-expect-error - This is bundled
+  const middleware = await import("./middleware.mjs");
+
+  const result: Response = await middleware.default(
+    [
+      {
+        name: middlewareInfo.name || "/",
+        page: middlewareInfo.page,
+        regex: middlewareInfo.matchers[0].regexp,
+      },
+    ],
+    {
+      headers: internalEvent.headers,
+      method: internalEvent.method || "GET",
       nextConfig: {
         basePath: NextConfig.basePath,
         i18n: NextConfig.i18n,
         trailingSlash: NextConfig.trailingSlash,
       },
       url,
-      body: getCloneableBody(req),
-      signal: signalFromNodeResponse(res),
+      body: convertBodyToReadableStream(internalEvent.body ?? ""),
     },
-    useCache: true,
-    onWarning: console.warn,
-  });
-  res.statusCode = result.response.status;
+  );
+  const statusCode = result.status;
 
   /* Apply override headers from middleware
     NextResponse.next({
@@ -108,9 +105,9 @@ export async function handleMiddleware(
     We can delete `x-middleware-override-headers` and check if the key starts with
     x-middleware-request- to set the req headers
   */
-  const responseHeaders = result.response.headers as Headers;
+  const responseHeaders = result.headers as Headers;
   const reqHeaders: Record<string, string> = {};
-  const resHeaders: Record<string, string> = {};
+  const resHeaders: Record<string, string | string[]> = {};
 
   responseHeaders.delete("x-middleware-override-headers");
   const xMiddlewareKey = "x-middleware-request-";
@@ -118,24 +115,31 @@ export async function handleMiddleware(
     if (key.startsWith(xMiddlewareKey)) {
       const k = key.substring(xMiddlewareKey.length);
       reqHeaders[k] = value;
-      req.headers[k] = value;
     } else {
-      resHeaders[key] = value;
-      res.setHeader(key, value);
+      if (key.toLowerCase() === "set-cookie") {
+        resHeaders[key] = resHeaders[key]
+          ? [...resHeaders[key], value]
+          : [value];
+      } else {
+        resHeaders[key] = value;
+      }
     }
   });
 
   // If the middleware returned a Redirect, we set the `Location` header with
   // the redirected url and end the response.
-  if (res.statusCode >= 300 && res.statusCode < 400) {
-    const location = result.response.headers
+  if (statusCode >= 300 && statusCode < 400) {
+    const location = result.headers
       .get("location")
-      ?.replace("http://localhost:3000", `https://${req.headers.host}`);
+      ?.replace(
+        "http://localhost:3000",
+        `https://${internalEvent.headers.host}`,
+      );
     // res.setHeader("Location", location);
     return {
       body: "",
       type: internalEvent.type,
-      statusCode: res.statusCode,
+      statusCode: statusCode,
       headers: {
         ...resHeaders,
         Location: location ?? "",
@@ -150,14 +154,15 @@ export async function handleMiddleware(
   let rewritten = false;
   let externalRewrite = false;
   let middlewareQueryString = internalEvent.query;
+  let newUrl = internalEvent.url;
   if (rewriteUrl) {
-    if (isExternal(rewriteUrl, req.headers.host)) {
-      req.url = rewriteUrl;
+    if (isExternal(rewriteUrl, internalEvent.headers.host)) {
+      newUrl = rewriteUrl;
       rewritten = true;
       externalRewrite = true;
     } else {
       const rewriteUrlObject = new URL(rewriteUrl);
-      req.url = rewriteUrlObject.pathname;
+      newUrl = rewriteUrlObject.pathname;
       //reset qs
       middlewareQueryString = {};
       rewriteUrlObject.searchParams.forEach((v: string, k: string) => {
@@ -169,24 +174,27 @@ export async function handleMiddleware(
 
   // If the middleware returned a `NextResponse`, pipe the body to res. This will return
   // the body immediately to the client.
-  if (result.response.body) {
+  if (result.body) {
     // transfer response body to res
-    const arrayBuffer = await result.response.arrayBuffer();
+    const arrayBuffer = await result.arrayBuffer();
     const buffer = Buffer.from(arrayBuffer);
-    res.end(buffer);
+    // res.end(buffer);
 
     // await pipeReadable(result.response.body, res);
     return {
       type: internalEvent.type,
-      ...convertRes(res),
+      statusCode: statusCode,
+      headers: resHeaders,
+      body: buffer.toString(),
+      isBase64Encoded: false,
     };
   }
 
   return {
     responseHeaders: resHeaders,
-    url: req.url ?? internalEvent.url,
+    url: newUrl,
     rawPath: rewritten
-      ? req.url ?? internalEvent.rawPath
+      ? newUrl ?? internalEvent.rawPath
       : internalEvent.rawPath,
     type: internalEvent.type,
     headers: { ...internalEvent.headers, ...reqHeaders },
diff --git a/packages/open-next/src/adapters/plugins/routing/util.ts b/packages/open-next/src/core/routing/util.ts
similarity index 54%
rename from packages/open-next/src/adapters/plugins/routing/util.ts
rename to packages/open-next/src/core/routing/util.ts
index c9ab4808c..c058834b0 100644
--- a/packages/open-next/src/adapters/plugins/routing/util.ts
+++ b/packages/open-next/src/core/routing/util.ts
@@ -1,76 +1,162 @@
-import { SendMessageCommand, SQSClient } from "@aws-sdk/client-sqs";
-import crypto from "crypto";
-import { ServerResponse } from "http";
+import crypto from "node:crypto";
+import { OutgoingHttpHeaders } from "node:http";
+import { request } from "node:https";
 
-import { BuildId, HtmlPages } from "../../config/index.js";
-import { IncomingMessage } from "../../http/request.js";
-import { ServerlessResponse } from "../../http/response.js";
-import { awsLogger, debug } from "../../logger.js";
+import { BuildId, HtmlPages } from "config/index.js";
+import type { IncomingMessage, StreamCreator } from "http/index.js";
+import { OpenNextNodeResponse } from "http/openNextResponse.js";
+import { parseHeaders } from "http/util.js";
+import type { MiddlewareManifest } from "types/next-types";
+import { InternalEvent } from "types/open-next.js";
 
-declare global {
-  var openNextDebug: boolean;
-  var openNextVersion: string;
-  var lastModified: number;
+import { isBinaryContentType } from "../../adapters/binary.js";
+import { debug, error } from "../../adapters/logger.js";
+
+export function isExternal(url?: string, host?: string) {
+  if (!url) return false;
+  const pattern = /^https?:\/\//;
+  if (host) {
+    return pattern.test(url) && !url.includes(host);
+  }
+  return pattern.test(url);
 }
 
-enum CommonHeaders {
-  CACHE_CONTROL = "cache-control",
-  NEXT_CACHE = "x-nextjs-cache",
+export function getUrlParts(url: string, isExternal: boolean) {
+  // NOTE: when redirect to a URL that contains search query params,
+  // compile breaks b/c it does not allow for the '?' character
+  // We can't use encodeURIComponent because modal interception contains
+  // characters that can't be encoded
+  url = url.replaceAll("?", "%3F");
+  if (!isExternal) {
+    return {
+      hostname: "",
+      pathname: url,
+      protocol: "",
+    };
+  }
+  const { hostname, pathname, protocol } = new URL(url);
+  return {
+    hostname,
+    pathname,
+    protocol,
+  };
+}
+
+export function convertRes(res: OpenNextNodeResponse) {
+  // Format Next.js response to Lambda response
+  const statusCode = res.statusCode || 200;
+  const headers = parseHeaders(res.headers);
+  const isBase64Encoded = isBinaryContentType(
+    Array.isArray(headers["content-type"])
+      ? headers["content-type"][0]
+      : headers["content-type"],
+  );
+  const encoding = isBase64Encoded ? "base64" : "utf8";
+  const body = res.body.toString(encoding);
+  return {
+    statusCode,
+    headers,
+    body,
+    isBase64Encoded,
+  };
+}
+
+export function convertQuery(query: Record<string, string | string[]>) {
+  const urlQuery: Record<string, string> = {};
+  Object.keys(query).forEach((k) => {
+    const v = query[k];
+    urlQuery[k] = Array.isArray(v) ? v.join(",") : v;
+  });
+  return urlQuery;
 }
 
-// Expected environment variables
-const { REVALIDATION_QUEUE_REGION, REVALIDATION_QUEUE_URL } = process.env;
+export function getMiddlewareMatch(middlewareManifest: MiddlewareManifest) {
+  const rootMiddleware = middlewareManifest.middleware["/"];
+  if (!rootMiddleware?.matchers) return [];
+  return rootMiddleware.matchers.map(({ regexp }) => new RegExp(regexp));
+}
 
-const sqsClient = new SQSClient({
-  region: REVALIDATION_QUEUE_REGION,
-  logger: awsLogger,
-});
+export function escapeRegex(str: string) {
+  let path = str.replace(/\(\.\)/g, "_µ1_");
 
-export async function proxyRequest(
-  req: IncomingMessage,
-  res: ServerlessResponse,
-) {
-  const HttpProxy = require("next/dist/compiled/http-proxy") as any;
+  path = path.replace(/\(\.{2}\)/g, "_µ2_");
 
-  const proxy = new HttpProxy({
-    changeOrigin: true,
-    ignorePath: true,
-    xfwd: true,
-  });
+  path = path.replace(/\(\.{3}\)/g, "_µ3_");
+
+  return path;
+}
+
+export function unescapeRegex(str: string) {
+  let path = str.replace(/_µ1_/g, "(.)");
+
+  path = path.replace(/_µ2_/g, "(..)");
+
+  path = path.replace(/_µ3_/g, "(...)");
 
+  return path;
+}
+
+export async function proxyRequest(
+  internalEvent: InternalEvent,
+  res: OpenNextNodeResponse,
+) {
+  const { url, headers, method, body } = internalEvent;
+  debug("proxyRequest", url);
   await new Promise<void>((resolve, reject) => {
-    proxy.on("proxyRes", (proxyRes: ServerResponse) => {
-      const body: Uint8Array[] = [];
-      proxyRes.on("data", function (chunk) {
-        body.push(chunk);
-      });
-      proxyRes.on("end", function () {
-        const newBody = Buffer.concat(body).toString();
-        debug(`Proxying response`, {
-          headers: proxyRes.getHeaders(),
-          body: newBody,
+    const { host: _host, ...filteredHeaders } = headers;
+    debug("filteredHeaders", filteredHeaders);
+    const req = request(
+      url,
+      {
+        headers: filteredHeaders,
+        method,
+        rejectUnauthorized: false,
+      },
+      (_res) => {
+        res.writeHead(_res.statusCode ?? 200, _res.headers);
+        if (_res.headers["content-encoding"] === "br") {
+          _res.pipe(require("node:zlib").createBrotliDecompress()).pipe(res);
+        } else if (_res.headers["content-encoding"] === "gzip") {
+          _res.pipe(require("node:zlib").createGunzip()).pipe(res);
+        } else {
+          _res.pipe(res);
+        }
+
+        _res.on("error", (e) => {
+          error("proxyRequest error", e);
+          res.end();
+          reject(e);
         });
-        res.end(newBody);
-        resolve();
-      });
-    });
+        res.on("end", () => {
+          resolve();
+        });
+      },
+    );
 
-    proxy.on("error", (err: any) => {
-      reject(err);
-    });
+    if (body && method !== "GET" && method !== "HEAD") {
+      req.write(body);
+    }
+    req.end();
+  });
+  // console.log("result", result);
+  // res.writeHead(result.status, resHeaders);
+  // res.end(await result.text());
+}
 
-    debug(`Proxying`, { url: req.url, headers: req.headers });
+declare global {
+  var openNextDebug: boolean;
+  var openNextVersion: string;
+  var lastModified: number;
+}
 
-    proxy.web(req, res, {
-      target: req.url,
-      headers: req.headers,
-    });
-  });
+enum CommonHeaders {
+  CACHE_CONTROL = "cache-control",
+  NEXT_CACHE = "x-nextjs-cache",
 }
 
 export function fixCacheHeaderForHtmlPages(
   rawPath: string,
-  headers: Record<string, string | undefined>,
+  headers: OutgoingHttpHeaders,
 ) {
   // WORKAROUND: `NextServer` does not set cache headers for HTML pages — https://github.com/serverless-stack/open-next#workaround-nextserver-does-not-set-cache-headers-for-html-pages
   if (HtmlPages.includes(rawPath) && headers[CommonHeaders.CACHE_CONTROL]) {
@@ -79,22 +165,21 @@ export function fixCacheHeaderForHtmlPages(
   }
 }
 
-export function fixSWRCacheHeader(
-  headers: Record<string, string | string[] | undefined>,
-) {
+export function fixSWRCacheHeader(headers: OutgoingHttpHeaders) {
   // WORKAROUND: `NextServer` does not set correct SWR cache headers — https://github.com/serverless-stack/open-next#workaround-nextserver-does-not-set-correct-swr-cache-headers
   let cacheControl = headers[CommonHeaders.CACHE_CONTROL];
   if (!cacheControl) return;
   if (Array.isArray(cacheControl)) {
     cacheControl = cacheControl.join(",");
   }
+  if (typeof cacheControl !== "string") return;
   headers[CommonHeaders.CACHE_CONTROL] = cacheControl.replace(
     /\bstale-while-revalidate(?!=)/,
     "stale-while-revalidate=2592000", // 30 days
   );
 }
 
-export function addOpenNextHeader(headers: Record<string, string | undefined>) {
+export function addOpenNextHeader(headers: OutgoingHttpHeaders) {
   headers["X-OpenNext"] = "1";
   if (globalThis.openNextDebug) {
     headers["X-OpenNext-Version"] = globalThis.openNextVersion;
@@ -104,7 +189,7 @@ export function addOpenNextHeader(headers: Record<string, string | undefined>) {
 export async function revalidateIfRequired(
   host: string,
   rawPath: string,
-  headers: Record<string, string | undefined>,
+  headers: OutgoingHttpHeaders,
   req?: IncomingMessage,
 ) {
   fixISRHeaders(headers);
@@ -139,14 +224,20 @@ export async function revalidateIfRequired(
       const lastModified =
         globalThis.lastModified > 0 ? globalThis.lastModified : "";
 
-      await sqsClient.send(
-        new SendMessageCommand({
-          QueueUrl: REVALIDATION_QUEUE_URL,
-          MessageDeduplicationId: hash(`${rawPath}-${lastModified}`),
-          MessageBody: JSON.stringify({ host, url: revalidateUrl }),
-          MessageGroupId: generateMessageGroupId(rawPath),
-        }),
-      );
+      // await sqsClient.send(
+      //   new SendMessageCommand({
+      //     QueueUrl: REVALIDATION_QUEUE_URL,
+      //     MessageDeduplicationId: hash(`${rawPath}-${lastModified}`),
+      //     MessageBody: JSON.stringify({ host, url: revalidateUrl }),
+      //     MessageGroupId: generateMessageGroupId(rawPath),
+      //   }),
+      // );
+
+      await globalThis.queue.send({
+        MessageBody: { host, url: revalidateUrl },
+        MessageDeduplicationId: hash(`${rawPath}-${lastModified}`),
+        MessageGroupId: generateMessageGroupId(rawPath),
+      });
     } catch (e) {
       debug(`Failed to revalidate stale page ${rawPath}`);
       debug(e);
@@ -198,7 +289,7 @@ function cyrb128(str: string) {
   return h1 >>> 0;
 }
 
-export function fixISRHeaders(headers: Record<string, string | undefined>) {
+export function fixISRHeaders(headers: OutgoingHttpHeaders) {
   if (headers[CommonHeaders.NEXT_CACHE] === "REVALIDATED") {
     headers[CommonHeaders.CACHE_CONTROL] =
       "private, no-cache, no-store, max-age=0, must-revalidate";
@@ -212,7 +303,10 @@ export function fixISRHeaders(headers: Record<string, string | undefined>) {
     const age = Math.round((Date.now() - globalThis.lastModified) / 1000);
     // extract s-maxage from cache-control
     const regex = /s-maxage=(\d+)/;
-    const match = headers[CommonHeaders.CACHE_CONTROL]?.match(regex);
+    const cacheControl = headers[CommonHeaders.CACHE_CONTROL];
+    debug("cache-control", cacheControl, globalThis.lastModified, Date.now());
+    if (typeof cacheControl !== "string") return;
+    const match = cacheControl.match(regex);
     const sMaxAge = match ? parseInt(match[1]) : undefined;
 
     // 31536000 is the default s-maxage value for SSG pages
@@ -235,3 +329,35 @@ export function fixISRHeaders(headers: Record<string, string | undefined>) {
   headers[CommonHeaders.CACHE_CONTROL] =
     "s-maxage=2, stale-while-revalidate=2592000";
 }
+
+/**
+ *
+ * @param internalEvent
+ * @param headers
+ * @param responseStream
+ * @returns
+ * @__PURE__
+ */
+export function createServerResponse(
+  internalEvent: InternalEvent,
+  headers: Record<string, string | string[] | undefined>,
+  responseStream?: StreamCreator,
+) {
+  return new OpenNextNodeResponse(
+    (_headers) => {
+      fixCacheHeaderForHtmlPages(internalEvent.rawPath, _headers);
+      fixSWRCacheHeader(_headers);
+      addOpenNextHeader(_headers);
+      fixISRHeaders(_headers);
+    },
+    async (_headers) => {
+      await revalidateIfRequired(
+        internalEvent.headers.host,
+        internalEvent.rawPath,
+        _headers,
+      );
+    },
+    responseStream,
+    headers,
+  );
+}
diff --git a/packages/open-next/src/core/routingHandler.ts b/packages/open-next/src/core/routingHandler.ts
new file mode 100644
index 000000000..9ac75c6bc
--- /dev/null
+++ b/packages/open-next/src/core/routingHandler.ts
@@ -0,0 +1,97 @@
+//TODO: Replace this with injected values in case of external routing
+// We could use open-next plugins to replace these values at build time
+import {
+  BuildId,
+  ConfigHeaders,
+  PrerenderManifest,
+  RoutesManifest,
+} from "config/index";
+import type { OutgoingHttpHeaders } from "http";
+import { InternalEvent, InternalResult } from "types/open-next";
+
+import { debug } from "../adapters/logger";
+import {
+  addNextConfigHeaders,
+  fixDataPage,
+  handleFallbackFalse,
+  handleRedirects,
+  handleRewrites,
+} from "./routing/matcher";
+import { handleMiddleware } from "./routing/middleware";
+
+export interface MiddlewareOutputEvent {
+  internalEvent: InternalEvent;
+  headers: OutgoingHttpHeaders;
+  isExternalRewrite: boolean;
+}
+
+export default async function routingHandler(
+  event: InternalEvent,
+): Promise<InternalResult | MiddlewareOutputEvent> {
+  const nextHeaders = addNextConfigHeaders(event, ConfigHeaders) ?? {};
+
+  let internalEvent = fixDataPage(event, BuildId);
+
+  internalEvent = handleFallbackFalse(internalEvent, PrerenderManifest);
+
+  const redirect = handleRedirects(internalEvent, RoutesManifest.redirects);
+  if (redirect) {
+    debug("redirect", redirect);
+    return redirect;
+  }
+
+  const middleware = await handleMiddleware(internalEvent);
+  let middlewareResponseHeaders: Record<string, string | string[]> = {};
+  if ("statusCode" in middleware) {
+    return middleware;
+  } else {
+    middlewareResponseHeaders = middleware.responseHeaders || {};
+    internalEvent = middleware;
+  }
+
+  let isExternalRewrite = middleware.externalRewrite ?? false;
+  if (!isExternalRewrite) {
+    // First rewrite to be applied
+    const beforeRewrites = handleRewrites(
+      internalEvent,
+      RoutesManifest.rewrites.beforeFiles,
+    );
+    internalEvent = beforeRewrites.internalEvent;
+    isExternalRewrite = beforeRewrites.isExternalRewrite;
+  }
+  const isStaticRoute = RoutesManifest.routes.static.some((route) =>
+    new RegExp(route.regex).test(event.rawPath),
+  );
+
+  if (!isStaticRoute && !isExternalRewrite) {
+    // Second rewrite to be applied
+    const afterRewrites = handleRewrites(
+      internalEvent,
+      RoutesManifest.rewrites.afterFiles,
+    );
+    internalEvent = afterRewrites.internalEvent;
+    isExternalRewrite = afterRewrites.isExternalRewrite;
+  }
+
+  const isDynamicRoute = RoutesManifest.routes.dynamic.some((route) =>
+    new RegExp(route.regex).test(event.rawPath),
+  );
+  if (!isDynamicRoute && !isStaticRoute && !isExternalRewrite) {
+    // Fallback rewrite to be applied
+    const fallbackRewrites = handleRewrites(
+      internalEvent,
+      RoutesManifest.rewrites.fallback,
+    );
+    internalEvent = fallbackRewrites.internalEvent;
+    isExternalRewrite = fallbackRewrites.isExternalRewrite;
+  }
+
+  return {
+    internalEvent,
+    headers: {
+      ...nextHeaders,
+      ...middlewareResponseHeaders,
+    },
+    isExternalRewrite,
+  };
+}
diff --git a/packages/open-next/src/adapters/plugins/util.ts b/packages/open-next/src/core/util.ts
similarity index 85%
rename from packages/open-next/src/adapters/plugins/util.ts
rename to packages/open-next/src/core/util.ts
index 5f8468978..ac851f010 100644
--- a/packages/open-next/src/adapters/plugins/util.ts
+++ b/packages/open-next/src/core/util.ts
@@ -1,20 +1,20 @@
 import fs from "node:fs";
 import path from "node:path";
 
-// @ts-ignore
-import NextServer from "next/dist/server/next-server.js";
-
 import {
   AppPathsManifestKeys,
   NextConfig,
   RoutesManifest,
-} from "../config/index.js";
-import { debug } from "../logger.js";
+} from "config/index.js";
+// @ts-ignore
+import NextServer from "next/dist/server/next-server.js";
+import type { MiddlewareManifest } from "types/next-types.js";
+
+import { debug } from "../adapters/logger.js";
 import {
   applyOverride as applyNextjsRequireHooksOverride,
   overrideHooks as overrideNextjsRequireHooks,
-} from "../require-hooks.js";
-import { MiddlewareManifest } from "../types/next-types.js";
+} from "./require-hooks.js";
 
 // WORKAROUND: Set `__NEXT_PRIVATE_PREBUNDLED_REACT` to use prebundled React — https://github.com/serverless-stack/open-next#workaround-set-__next_private_prebundled_react-to-use-prebundled-react
 // Step 1: Need to override the require hooks for React before Next.js server
@@ -28,11 +28,12 @@ overrideNextjsRequireHooks(NextConfig);
 applyNextjsRequireHooksOverride();
 //#endOverride
 
-//#override requestHandler
 // @ts-ignore
 export const requestHandler = new NextServer.default({
+  //#override requestHandlerHost
   hostname: "localhost",
   port: 3000,
+  //#endOverride
   conf: {
     ...NextConfig,
     // Next.js compression should be disabled because of a bug in the bundled
@@ -42,6 +43,13 @@ export const requestHandler = new NextServer.default({
     // our own cache handler to store the cache on S3.
     experimental: {
       ...NextConfig.experimental,
+      // This uses the request.headers.host as the URL
+      // https://github.com/vercel/next.js/blob/canary/packages/next/src/server/next-server.ts#L1749-L1754
+      //#override trustHostHeader
+      trustHostHeader: true,
+      //#endOverride
+
+      //TODO: change env.LAMBDA_TASK_ROOT
       incrementalCacheHandlerPath: `${process.env.LAMBDA_TASK_ROOT}/cache.cjs`,
     },
   },
@@ -49,7 +57,6 @@ export const requestHandler = new NextServer.default({
   dev: false,
   dir: __dirname,
 }).getRequestHandler();
-//#endOverride
 
 export function getMiddlewareMatch(middlewareManifest: MiddlewareManifest) {
   const rootMiddleware = middlewareManifest.middleware["/"];
diff --git a/packages/open-next/src/http/index.ts b/packages/open-next/src/http/index.ts
new file mode 100644
index 000000000..49efb2fe4
--- /dev/null
+++ b/packages/open-next/src/http/index.ts
@@ -0,0 +1,4 @@
+// @__PURE__
+export * from "./openNextResponse.js";
+// @__PURE__
+export * from "./request.js";
diff --git a/packages/open-next/src/http/openNextResponse.ts b/packages/open-next/src/http/openNextResponse.ts
new file mode 100644
index 000000000..ff8610493
--- /dev/null
+++ b/packages/open-next/src/http/openNextResponse.ts
@@ -0,0 +1,144 @@
+import { OutgoingHttpHeader, OutgoingHttpHeaders } from "http";
+import { Transform, TransformCallback, Writable } from "stream";
+
+import { convertHeader, parseCookies, parseHeaders } from "./util";
+
+const SET_COOKIE_HEADER = "set-cookie";
+
+export interface StreamCreator {
+  writeHeaders(prelude: {
+    statusCode: number;
+    cookies: string[];
+    headers: Record<string, string>;
+  }): Writable;
+  // Just to fix an issue with aws lambda streaming with empty body
+  onWrite?: () => void;
+  onFinish: () => void;
+}
+
+// We only need to implement the methods that are used by next.js
+export class OpenNextNodeResponse extends Transform {
+  statusCode: number | undefined;
+  statusMessage: string | undefined;
+  headers: OutgoingHttpHeaders = {};
+  private _cookies: string[] = [];
+  private responseStream?: Writable;
+  headersSent: boolean = false;
+  _chunks: Buffer[] = [];
+
+  constructor(
+    private fixHeaders: (headers: OutgoingHttpHeaders) => void,
+    onEnd: (headers: OutgoingHttpHeaders) => Promise<void>,
+    private streamCreator?: StreamCreator,
+    private initialHeaders?: OutgoingHttpHeaders,
+  ) {
+    super();
+    if (initialHeaders && initialHeaders[SET_COOKIE_HEADER]) {
+      this._cookies = parseCookies(
+        initialHeaders[SET_COOKIE_HEADER] as string | string[],
+      ) as string[];
+    }
+    this.once("finish", () => {
+      if (!this.headersSent) {
+        this.flushHeaders();
+      }
+      onEnd(this.headers);
+      this.streamCreator?.onFinish();
+    });
+  }
+
+  get finished() {
+    return this.writableFinished && this.responseStream?.writableFinished;
+  }
+
+  setHeader(name: string, value: string | string[]): this {
+    const key = name.toLowerCase();
+    if (key === SET_COOKIE_HEADER) {
+      this._cookies.push(convertHeader(value));
+      this.headers[key] = this._cookies;
+    } else {
+      this.headers[key] = value;
+    }
+
+    return this;
+  }
+
+  removeHeader(name: string): this {
+    const key = name.toLowerCase();
+    if (key === SET_COOKIE_HEADER) {
+      this._cookies = [];
+    } else {
+      delete this.headers[key];
+    }
+    return this;
+  }
+
+  hasHeader(name: string): boolean {
+    const key = name.toLowerCase();
+    if (key === SET_COOKIE_HEADER) {
+      return this._cookies.length > 0;
+    }
+    return this.headers[key] !== undefined;
+  }
+
+  getHeaders(): OutgoingHttpHeaders {
+    return this.headers;
+  }
+
+  getHeader(name: string): OutgoingHttpHeader | undefined {
+    return this.headers[name.toLowerCase()];
+  }
+
+  // Only used directly in next@14+
+  flushHeaders() {
+    this.headersSent = true;
+    this.fixHeaders(this.headers);
+    if (this.initialHeaders) {
+      this.headers = {
+        ...this.headers,
+        ...this.initialHeaders,
+      };
+    }
+
+    if (this.streamCreator) {
+      this.responseStream = this.streamCreator?.writeHeaders({
+        statusCode: this.statusCode ?? 200,
+        cookies: this._cookies,
+        headers: parseHeaders(this.headers),
+      });
+      this.pipe(this.responseStream);
+    }
+  }
+
+  // Might be used in next page api routes
+  writeHead(statusCode: number, headers?: OutgoingHttpHeaders): this {
+    this.statusCode = statusCode;
+    if (headers) {
+      this.headers = headers;
+    }
+    this.flushHeaders();
+    return this;
+  }
+
+  get body() {
+    return Buffer.concat(this._chunks);
+  }
+
+  private _internalWrite(chunk: any, encoding: BufferEncoding) {
+    this._chunks.push(Buffer.from(chunk, encoding));
+    this.push(chunk, encoding);
+    this.streamCreator?.onWrite?.();
+  }
+
+  _transform(
+    chunk: any,
+    encoding: BufferEncoding,
+    callback: TransformCallback,
+  ): void {
+    if (!this.headersSent) {
+      this.flushHeaders();
+    }
+    this._internalWrite(chunk, encoding);
+    callback();
+  }
+}
diff --git a/packages/open-next/src/adapters/http/request.ts b/packages/open-next/src/http/request.ts
similarity index 98%
rename from packages/open-next/src/adapters/http/request.ts
rename to packages/open-next/src/http/request.ts
index 180132562..d33b13955 100644
--- a/packages/open-next/src/adapters/http/request.ts
+++ b/packages/open-next/src/http/request.ts
@@ -16,7 +16,7 @@ export class IncomingMessage extends http.IncomingMessage {
     method: string;
     url: string;
     headers: Record<string, string>;
-    body: Buffer;
+    body?: Buffer;
     remoteAddress: string;
   }) {
     super({
diff --git a/packages/open-next/src/http/util.ts b/packages/open-next/src/http/util.ts
new file mode 100644
index 000000000..0e3be5fdd
--- /dev/null
+++ b/packages/open-next/src/http/util.ts
@@ -0,0 +1,42 @@
+import http from "node:http";
+
+export const parseHeaders = (
+  headers?: http.OutgoingHttpHeader[] | http.OutgoingHttpHeaders,
+) => {
+  const result: Record<string, string> = {};
+  if (!headers) {
+    return result;
+  }
+
+  for (const [key, value] of Object.entries(headers)) {
+    if (value === undefined) {
+      continue;
+    } else {
+      result[key] = convertHeader(value);
+    }
+  }
+
+  return result;
+};
+
+export const convertHeader = (header: http.OutgoingHttpHeader) => {
+  if (typeof header === "string") {
+    return header;
+  } else if (Array.isArray(header)) {
+    return header.join(",");
+  } else {
+    return String(header);
+  }
+};
+
+export function parseCookies(
+  cookies?: string | string[],
+): string[] | undefined {
+  if (!cookies) return;
+
+  if (typeof cookies === "string") {
+    return cookies.split(/(?<!Expires=\w+),/i).map((c) => c.trim());
+  }
+
+  return cookies;
+}
diff --git a/packages/open-next/src/index.ts b/packages/open-next/src/index.ts
index 7ac28c351..9fb8f375f 100644
--- a/packages/open-next/src/index.ts
+++ b/packages/open-next/src/index.ts
@@ -1,5 +1,8 @@
 #!/usr/bin/env node
 
+import * as esbuild from "esbuild";
+import path from "path";
+
 import { build } from "./build.js";
 
 const command = process.argv[2];
@@ -8,22 +11,23 @@ if (command !== "build") printHelp();
 const args = parseArgs();
 if (Object.keys(args).includes("--help")) printHelp();
 
-build({
-  buildCommand: args["--build-command"],
-  buildOutputPath: args["--build-output-path"],
-  appPath: args["--app-path"],
-  minify: Object.keys(args).includes("--minify"),
-  streaming: Object.keys(args).includes("--streaming"),
-  dangerous: {
-    disableDynamoDBCache: Object.keys(args).includes(
-      "--dangerously-disable-dynamodb-cache",
-    ),
-    disableIncrementalCache: Object.keys(args).includes(
-      "--dangerously-disable-incremental-cache",
-    ),
-  },
+//TODO: validate config file
+
+const outputTmpPath = path.join(process.cwd(), ".open-next", ".build");
+
+// Compile open-next.config.ts
+esbuild.buildSync({
+  entryPoints: [path.join(process.cwd(), "open-next.config.ts")],
+  outfile: path.join(outputTmpPath, "open-next.config.js"),
+  bundle: true,
+  format: "cjs",
+  target: ["node18"],
 });
 
+const config = await import(outputTmpPath + "/open-next.config.js");
+
+build(config.default);
+
 function parseArgs() {
   return process.argv.slice(2).reduce(
     (acc, key, ind, self) => {
diff --git a/packages/open-next/src/plugins/edge.ts b/packages/open-next/src/plugins/edge.ts
new file mode 100644
index 000000000..5f89f9c52
--- /dev/null
+++ b/packages/open-next/src/plugins/edge.ts
@@ -0,0 +1,108 @@
+import { readFileSync } from "node:fs";
+
+import { Plugin } from "esbuild";
+
+import {
+  loadAppPathsManifestKeys,
+  loadBuildId,
+  loadConfig,
+  loadConfigHeaders,
+  loadHtmlPages,
+  loadMiddlewareManifest,
+  loadPrerenderManifest,
+  loadRoutesManifest,
+} from "../adapters/config/util.js";
+
+export interface IPluginSettings {
+  nextDir: string;
+  edgeFunctionHandlerPath?: string;
+  entryFiles: string[];
+}
+
+/**
+ * TODO: Handle wasm import
+ * @param opts.nextDir - The path to the .next directory
+ * @param opts.edgeFunctionHandlerPath - The path to the edgeFunctionHandler.js file that we'll use to bundle the routing
+ * @param opts.entryFiles - The entry files that we'll inject into the edgeFunctionHandler.js file
+ * @returns
+ */
+export function openNextEdgePlugins({
+  nextDir,
+  edgeFunctionHandlerPath,
+  entryFiles,
+}: IPluginSettings): Plugin {
+  return {
+    name: "opennext-edge",
+    setup(build) {
+      if (edgeFunctionHandlerPath) {
+        // If we bundle the routing, we need to resolve the middleware
+        build.onResolve({ filter: /\.\/middleware.mjs/g }, () => {
+          return {
+            path: edgeFunctionHandlerPath,
+          };
+        });
+      }
+
+      // We inject the entry files into the edgeFunctionHandler
+      build.onLoad({ filter: /\/edgeFunctionHandler.js/g }, async (args) => {
+        let contents = readFileSync(args.path, "utf-8");
+        contents = `
+globalThis._ENTRIES = {};
+globalThis.self = globalThis;
+globalThis.process = {env: {}}
+
+import {Buffer} from "node:buffer";
+globalThis.Buffer = Buffer;
+
+import {AsyncLocalStorage} from "node:async_hooks";
+globalThis.AsyncLocalStorage = AsyncLocalStorage;
+${entryFiles?.map((file) => `require("${file}");`).join("\n")}
+${contents}        
+        `;
+        return {
+          contents,
+        };
+      });
+
+      build.onLoad({ filter: /adapters\/config\/index.ts/g }, async () => {
+        console.log("opennext-config-plugin");
+        const NextConfig = loadConfig(nextDir);
+        const BuildId = loadBuildId(nextDir);
+        const HtmlPages = loadHtmlPages(nextDir);
+        const RoutesManifest = loadRoutesManifest(nextDir);
+        const ConfigHeaders = loadConfigHeaders(nextDir);
+        const PrerenderManifest = loadPrerenderManifest(nextDir);
+        const AppPathsManifestKeys = loadAppPathsManifestKeys(nextDir);
+        const MiddlewareManifest = loadMiddlewareManifest(nextDir);
+
+        const contents = `
+  import path from "path";
+  
+  import { debug } from "../logger";
+  
+  if(!globalThis.__dirname) {
+    globalThis.__dirname = ""
+  }
+  
+  export const NEXT_DIR = path.join(__dirname, ".next");
+  export const OPEN_NEXT_DIR = path.join(__dirname, ".open-next");
+  
+  debug({ NEXT_DIR, OPEN_NEXT_DIR });
+  
+  export const NextConfig = ${JSON.stringify(NextConfig)};
+  export const BuildId = ${JSON.stringify(BuildId)};
+  export const HtmlPages = ${JSON.stringify(HtmlPages)};
+  export const RoutesManifest = ${JSON.stringify(RoutesManifest)};
+  export const ConfigHeaders = ${JSON.stringify(ConfigHeaders)};
+  export const PrerenderManifest = ${JSON.stringify(PrerenderManifest)};
+  export const AppPathsManifestKeys = ${JSON.stringify(AppPathsManifestKeys)};
+  export const MiddlewareManifest = ${JSON.stringify(MiddlewareManifest)};
+  
+          `;
+        return {
+          contents,
+        };
+      });
+    },
+  };
+}
diff --git a/packages/open-next/src/plugin.ts b/packages/open-next/src/plugins/replacement.ts
similarity index 70%
rename from packages/open-next/src/plugin.ts
rename to packages/open-next/src/plugins/replacement.ts
index 90060f36a..60279ed33 100644
--- a/packages/open-next/src/plugin.ts
+++ b/packages/open-next/src/plugins/replacement.ts
@@ -1,13 +1,13 @@
 import { readFile } from "node:fs/promises";
-import path from "node:path";
 
 import { Plugin } from "esbuild";
 
-import logger from "./logger.js";
+import logger from "../logger.js";
 
 export interface IPluginSettings {
   target: RegExp;
-  replacements: string[];
+  replacements?: string[];
+  deletes?: string[];
   name?: string;
 }
 
@@ -18,7 +18,8 @@ const importPattern = /\/\/#import([\s\S]*?)\n\/\/#endImport/gm;
  *
  * openNextPlugin({
  *   target: /plugins\/default\.js/g,
- *   replacements: ["./13_4_13.js"],
+ *   replacements: [require.resolve("./plugins/default.js")],
+ *   deletes: ["id1"],
  * })
  *
  * To inject arbritary code by using (import at top of file):
@@ -43,12 +44,14 @@ const importPattern = /\/\/#import([\s\S]*?)\n\/\/#endImport/gm;
  *
  * @param opts.target - the target file to replace
  * @param opts.replacements - list of files used to replace the imports/overrides in the target
- *                          - the path is relative to the target path
+ *                          - the path is absolute
+ * @param opts.deletes - list of ids to delete from the target
  * @returns
  */
-export default function openNextPlugin({
+export function openNextReplacementPlugin({
   target,
   replacements,
+  deletes,
   name,
 }: IPluginSettings): Plugin {
   return {
@@ -57,9 +60,18 @@ export default function openNextPlugin({
       build.onLoad({ filter: target }, async (args) => {
         let contents = await readFile(args.path, "utf-8");
 
-        await Promise.all(
-          replacements.map(async (fp) => {
-            const p = path.join(args.path, "..", fp);
+        await Promise.all([
+          ...(deletes ?? []).map(async (id) => {
+            const pattern = new RegExp(
+              `\/\/#override (${id})\n([\\s\\S]*?)\/\/#endOverride`,
+            );
+            logger.debug(
+              `Open-next plugin ${name} -- Deleting override for ${id}`,
+            );
+            contents = contents.replace(pattern, "");
+          }),
+          ...(replacements ?? []).map(async (fp) => {
+            const p = fp;
             const replacementFile = await readFile(p, "utf-8");
             const matches = replacementFile.matchAll(overridePattern);
 
@@ -80,7 +92,7 @@ export default function openNextPlugin({
               contents = contents.replace(pattern, replacement);
             }
           }),
-        );
+        ]);
 
         return {
           contents,
diff --git a/packages/open-next/src/plugins/resolve.ts b/packages/open-next/src/plugins/resolve.ts
new file mode 100644
index 000000000..54a751a06
--- /dev/null
+++ b/packages/open-next/src/plugins/resolve.ts
@@ -0,0 +1,52 @@
+import { readFileSync } from "node:fs";
+
+import { Plugin } from "esbuild";
+import type {
+  IncludedConverter,
+  IncludedIncrementalCache,
+  IncludedQueue,
+  IncludedTagCache,
+  IncludedWrapper,
+} from "types/open-next";
+
+export interface IPluginSettings {
+  overrides: {
+    wrapper?: IncludedWrapper;
+    converter?: IncludedConverter;
+    // Right now theses do nothing since there is only one implementation
+    tag?: IncludedTagCache;
+    queue?: IncludedQueue;
+    incrementalCache?: IncludedIncrementalCache;
+  };
+}
+
+/**
+ * @param opts.overrides - The name of the overrides to use
+ * @returns
+ */
+export function openNextResolvePlugin({ overrides }: IPluginSettings): Plugin {
+  return {
+    name: "opennext-resolve",
+    setup(build) {
+      build.onLoad({ filter: /core\/resolve.js/g }, async (args) => {
+        let contents = readFileSync(args.path, "utf-8");
+        if (overrides?.wrapper) {
+          contents = contents.replace(
+            "../wrappers/aws-lambda.js",
+            `../wrappers/${overrides.wrapper}.js`,
+          );
+        }
+        if (overrides?.converter) {
+          console.log("converter", overrides.converter);
+          contents = contents.replace(
+            "../converters/aws-apigw-v2.js",
+            `../converters/${overrides.converter}.js`,
+          );
+        }
+        return {
+          contents,
+        };
+      });
+    },
+  };
+}
diff --git a/packages/open-next/src/queue/sqs.ts b/packages/open-next/src/queue/sqs.ts
new file mode 100644
index 000000000..cd3c90524
--- /dev/null
+++ b/packages/open-next/src/queue/sqs.ts
@@ -0,0 +1,27 @@
+import { SendMessageCommand, SQSClient } from "@aws-sdk/client-sqs";
+
+import { awsLogger } from "../adapters/logger";
+import { Queue } from "./types";
+
+// Expected environment variables
+const { REVALIDATION_QUEUE_REGION, REVALIDATION_QUEUE_URL } = process.env;
+
+const sqsClient = new SQSClient({
+  region: REVALIDATION_QUEUE_REGION,
+  logger: awsLogger,
+});
+
+const queue: Queue = {
+  send: async ({ MessageBody, MessageDeduplicationId, MessageGroupId }) => {
+    await sqsClient.send(
+      new SendMessageCommand({
+        QueueUrl: REVALIDATION_QUEUE_URL,
+        MessageBody: JSON.stringify(MessageBody),
+        MessageDeduplicationId,
+        MessageGroupId,
+      }),
+    );
+  },
+};
+
+export default queue;
diff --git a/packages/open-next/src/queue/types.ts b/packages/open-next/src/queue/types.ts
new file mode 100644
index 000000000..4916b7f89
--- /dev/null
+++ b/packages/open-next/src/queue/types.ts
@@ -0,0 +1,12 @@
+export interface QueueMessage {
+  MessageDeduplicationId: string;
+  MessageBody: {
+    host: string;
+    url: string;
+  };
+  MessageGroupId: string;
+}
+
+export interface Queue {
+  send(message: QueueMessage): Promise<void>;
+}
diff --git a/packages/open-next/src/adapters/types/aws-lambda.ts b/packages/open-next/src/types/aws-lambda.ts
similarity index 100%
rename from packages/open-next/src/adapters/types/aws-lambda.ts
rename to packages/open-next/src/types/aws-lambda.ts
diff --git a/packages/open-next/src/adapters/types/next-types.ts b/packages/open-next/src/types/next-types.ts
similarity index 92%
rename from packages/open-next/src/adapters/types/next-types.ts
rename to packages/open-next/src/types/next-types.ts
index 84f5408ad..78bd5387f 100644
--- a/packages/open-next/src/adapters/types/next-types.ts
+++ b/packages/open-next/src/types/next-types.ts
@@ -1,8 +1,8 @@
 // NOTE: add more next config typings as they become relevant
 
-import { InternalEvent } from "../event-mapper.js";
-import { IncomingMessage } from "../http/request.js";
-import { ServerlessResponse } from "../http/response.js";
+import type { IncomingMessage, OpenNextNodeResponse } from "http/index.js";
+
+import { InternalEvent } from "./open-next";
 
 type RemotePattern = {
   protocol?: "http" | "https";
@@ -151,7 +151,7 @@ export type Options = {
 export interface PluginHandler {
   (
     req: IncomingMessage,
-    res: ServerlessResponse,
+    res: OpenNextNodeResponse,
     options: Options,
-  ): Promise<ServerlessResponse | undefined>;
+  ): Promise<OpenNextNodeResponse | undefined>;
 }
diff --git a/packages/open-next/src/types/open-next.ts b/packages/open-next/src/types/open-next.ts
new file mode 100644
index 000000000..868ea004d
--- /dev/null
+++ b/packages/open-next/src/types/open-next.ts
@@ -0,0 +1,267 @@
+import type { Readable } from "node:stream";
+
+import { StreamCreator } from "http/index.js";
+
+import { WarmerEvent, WarmerResponse } from "../adapters/warmer-function";
+import { IncrementalCache } from "../cache/incremental/types";
+import { TagCache } from "../cache/tag/types";
+import { Queue } from "../queue/types";
+
+export type BaseEventOrResult<T extends string = string> = {
+  type: T;
+};
+
+export type InternalEvent = {
+  readonly method: string;
+  readonly rawPath: string;
+  readonly url: string;
+  readonly body?: Buffer;
+  readonly headers: Record<string, string>;
+  readonly query: Record<string, string | string[]>;
+  readonly cookies: Record<string, string>;
+  readonly remoteAddress: string;
+} & BaseEventOrResult<"core">;
+
+export type InternalResult = {
+  statusCode: number;
+  headers: Record<string, string | string[]>;
+  body: string;
+  isBase64Encoded: boolean;
+} & BaseEventOrResult<"core">;
+
+export interface DangerousOptions {
+  /**
+   * The dynamo db cache is used for revalidateTags and revalidatePath.
+   * @default false
+   */
+  disableDynamoDBCache?: boolean;
+  /**
+   * The incremental cache is used for ISR and SSG.
+   * Disable this only if you use only SSR
+   * @default false
+   */
+  disableIncrementalCache?: boolean;
+}
+
+export type LazyLoadedOverride<T> = () => Promise<T>;
+
+export type OpenNextHandler<
+  E extends BaseEventOrResult = InternalEvent,
+  R extends BaseEventOrResult = InternalResult,
+> = (event: E, responseStream?: StreamCreator) => Promise<R>;
+
+export type Converter<
+  E extends BaseEventOrResult = InternalEvent,
+  R extends BaseEventOrResult = InternalResult,
+> = {
+  convertFrom: (event: any) => Promise<E>;
+  convertTo: (result: R) => any;
+};
+
+export type Wrapper<
+  E extends BaseEventOrResult = InternalEvent,
+  R extends BaseEventOrResult = InternalResult,
+> = (
+  handler: OpenNextHandler<E, R>,
+  converter: Converter<E, R>,
+) => Promise<(...args: any[]) => any>;
+
+type Warmer = (warmerId: string) => Promise<
+  {
+    statusCode: number;
+    payload: {
+      serverId: string;
+    };
+    type: "warmer";
+  }[]
+>;
+
+type ImageLoader = (url: string) => Promise<{
+  body?: Readable;
+  contentType?: string;
+  cacheControl?: string;
+}>;
+
+export type IncludedWrapper =
+  | "aws-lambda"
+  | "aws-lambda-streaming"
+  | "node"
+  | "cloudflare";
+
+export type IncludedConverter =
+  | "aws-apigw-v2"
+  | "aws-apigw-v1"
+  | "aws-cloudfront"
+  | "edge"
+  | "node"
+  | "sqs-revalidate"
+  | "dummy";
+
+export type IncludedQueue = "sqs";
+
+export type IncludedIncrementalCache = "s3";
+
+export type IncludedTagCache = "dynamodb";
+
+export interface DefaultOverrideOptions<
+  E extends BaseEventOrResult = InternalEvent,
+  R extends BaseEventOrResult = InternalResult,
+> {
+  /**
+   * This is the main entrypoint of your app.
+   * @default "aws-lambda"
+   */
+  wrapper?: IncludedWrapper | LazyLoadedOverride<Wrapper<E, R>>;
+
+  /**
+   * This code convert the event to InternalEvent and InternalResult to the expected output.
+   * @default "aws-apigw-v2"
+   */
+  converter?: IncludedConverter | LazyLoadedOverride<Converter<E, R>>;
+}
+
+export interface OverrideOptions extends DefaultOverrideOptions {
+  /**
+   * Add possibility to override the default s3 cache. Used for fetch cache and html/rsc/json cache.
+   * @default "s3"
+   */
+  incrementalCache?: "s3" | LazyLoadedOverride<IncrementalCache>;
+
+  /**
+   * Add possibility to override the default tag cache. Used for revalidateTags and revalidatePath.
+   * @default "dynamodb"
+   */
+  tagCache?: "dynamodb" | LazyLoadedOverride<TagCache>;
+
+  /**
+   * Add possibility to override the default queue. Used for isr.
+   * @default "sqs"
+   */
+  queue?: "sqs" | LazyLoadedOverride<Queue>;
+}
+
+export interface DefaultFunctionOptions<
+  E extends BaseEventOrResult = InternalEvent,
+  R extends BaseEventOrResult = InternalResult,
+> {
+  /**
+   * Minify the server bundle.
+   * @default false
+   */
+  minify?: boolean;
+  /**
+   * Print debug information.
+   * @default false
+   */
+  debug?: boolean;
+  /**
+   * Enable overriding the default lambda.
+   */
+  override?: DefaultOverrideOptions<E, R>;
+}
+
+interface FunctionOptions extends DefaultFunctionOptions {
+  /**
+   * TODO: implement edge runtime
+   * @default "node"
+   */
+  runtime?: "node" | "edge";
+  /**
+   * Here you should specify all the routes you want to use.
+   * If not provided, all the routes will be used.
+   * @default []
+   */
+  routes?: string[];
+  /**
+   * Enable streaming mode.
+   * @default false
+   */
+  streaming?: boolean;
+  /**
+   * Enable overriding the default lambda.
+   */
+  override?: OverrideOptions;
+}
+
+export interface BuildOptions {
+  functions: {
+    default: Omit<FunctionOptions, "routes">;
+    [key: string]: FunctionOptions;
+  };
+
+  /**
+   * Override the default middleware
+   * If you set this options, the middleware need to be deployed separately.
+   * It supports both edge and node runtime.
+   * TODO: actually implement it
+   * @default undefined
+   */
+  middleware?: DefaultFunctionOptions & {
+    //We force the middleware to be a function
+    external: true;
+  };
+
+  /**
+   * Override the default warmer
+   * By default, works for lambda only.
+   * If you override this, you'll need to handle the warmer event in the wrapper
+   * @default undefined
+   */
+  warmer?: DefaultFunctionOptions<WarmerEvent, WarmerResponse> & {
+    invokeFunction: "aws-lambda" | LazyLoadedOverride<Warmer>;
+  };
+
+  /**
+   * Override the default revalidate function
+   * By default, works for lambda and on SQS event.
+   * Supports only node runtime
+   */
+  revalidate?: DefaultFunctionOptions<
+    { host: string; url: string; type: "revalidate" },
+    { type: "revalidate" }
+  >;
+
+  /**
+   * Override the default revalidate function
+   * By default, works on lambda and for S3 key.
+   * Supports only node runtime
+   */
+  imageOptimization?: DefaultFunctionOptions & {
+    loader?: "s3" | LazyLoadedOverride<ImageLoader>;
+  };
+
+  /**
+   * Override the default initialization function
+   * By default, works for lambda and on SQS event.
+   * Supports only node runtime
+   */
+  initializationFunction?: DefaultFunctionOptions & {
+    tagCache?: "dynamodb" | LazyLoadedOverride<TagCache>;
+  };
+
+  /**
+   * The command to build the Next.js app.
+   * @default `npm run build`, `yarn build`, or `pnpm build` based on the lock file found in the app's directory or any of its parent directories.
+   * @example
+   * ```ts
+   * build({
+   *   buildCommand: "pnpm custom:build",
+   * });
+   * ```
+   */
+  /**
+   * Dangerous options. This break some functionnality but can be useful in some cases.
+   */
+  dangerous?: DangerousOptions;
+  buildCommand?: string;
+  /**
+   * The path to the target folder of build output from the `buildCommand` option (the path which will contain the `.next` and `.open-next` folders). This path is relative from the current process.cwd().
+   * @default "."
+   */
+  buildOutputPath?: string;
+  /**
+   * The path to the root of the Next.js app's source code. This path is relative from the current process.cwd().
+   * @default "."
+   */
+  appPath?: string;
+}
diff --git a/packages/open-next/src/wrappers/aws-lambda-streaming.ts b/packages/open-next/src/wrappers/aws-lambda-streaming.ts
new file mode 100644
index 000000000..d14c195c0
--- /dev/null
+++ b/packages/open-next/src/wrappers/aws-lambda-streaming.ts
@@ -0,0 +1,110 @@
+import { Writable } from "node:stream";
+import zlib from "node:zlib";
+
+import { APIGatewayProxyEventV2 } from "aws-lambda";
+import { StreamCreator } from "http/index.js";
+import { Wrapper } from "types/open-next";
+
+import { error } from "../adapters/logger";
+import { WarmerEvent } from "../adapters/warmer-function";
+
+type AwsLambdaEvent = APIGatewayProxyEventV2 | WarmerEvent;
+
+type AwsLambdaReturn = void;
+const handler: Wrapper = async (handler, converter) =>
+  awslambda.streamifyResponse(
+    async (event: AwsLambdaEvent, responseStream): Promise<AwsLambdaReturn> => {
+      const internalEvent = await converter.convertFrom(event);
+      let _hasWriten = false;
+      let _headersSent = false;
+
+      //Handle compression
+      const acceptEncoding = internalEvent.headers?.["accept-encoding"] ?? "";
+      let contentEncoding: string;
+      let compressedStream: Writable | undefined;
+
+      responseStream.on("error", (err) => {
+        error(err);
+        responseStream.end();
+      });
+
+      if (acceptEncoding.includes("br")) {
+        contentEncoding = "br";
+        compressedStream = zlib.createBrotliCompress({
+          flush: zlib.constants.BROTLI_OPERATION_FLUSH,
+          finishFlush: zlib.constants.BROTLI_OPERATION_FINISH,
+        });
+        compressedStream.pipe(responseStream);
+      } else if (acceptEncoding.includes("gzip")) {
+        contentEncoding = "gzip";
+        compressedStream = zlib.createGzip({
+          flush: zlib.constants.Z_SYNC_FLUSH,
+        });
+        compressedStream.pipe(responseStream);
+      } else if (acceptEncoding.includes("deflate")) {
+        contentEncoding = "deflate";
+        compressedStream = zlib.createDeflate({
+          flush: zlib.constants.Z_SYNC_FLUSH,
+        });
+        compressedStream.pipe(responseStream);
+      } else {
+        contentEncoding = "identity";
+        compressedStream = responseStream;
+      }
+
+      const streamCreator: StreamCreator = {
+        writeHeaders: (_prelude) => {
+          responseStream.cork();
+          // FIXME: This is extracted from the docker lambda node 18 runtime
+          // https://gist.github.com/conico974/13afd708af20711b97df439b910ceb53#file-index-mjs-L921-L932
+          // We replace their write with ours which are inside a setImmediate
+          // This way it seems to work all the time
+          // I think we can't ship this code as it is, it could break at anytime if they decide to change the runtime and they already did it in the past
+
+          responseStream.setContentType(
+            "application/vnd.awslambda.http-integration-response",
+          );
+          _prelude.headers["content-encoding"] = contentEncoding;
+          const prelude = JSON.stringify(_prelude);
+
+          // Try to flush the buffer to the client to invoke
+          // the streaming. This does not work 100% of the time.
+
+          responseStream.write("\n\n");
+
+          responseStream.write(prelude);
+
+          responseStream.write(new Uint8Array(8));
+
+          if (responseStream.writableCorked) {
+            for (let i = 0; i < responseStream.writableCorked; i++) {
+              responseStream.uncork();
+            }
+          }
+
+          _headersSent = true;
+
+          return compressedStream ?? responseStream;
+        },
+        onWrite: () => {
+          _hasWriten = true;
+          // Force flushing data, seems necessary for aws lambda streaming to work reliably
+          // We need to reevaluate this if it causes issues on other platforms
+          if (compressedStream?.writableCorked) {
+            compressedStream?.uncork();
+          }
+        },
+        onFinish: () => {
+          if (!_hasWriten) {
+            compressedStream?.end(new Uint8Array(8));
+          }
+        },
+      };
+
+      const response = await handler(internalEvent, streamCreator);
+
+      return converter.convertTo(response);
+    },
+  );
+
+export default handler;
diff --git a/packages/open-next/src/wrappers/aws-lambda.ts b/packages/open-next/src/wrappers/aws-lambda.ts
new file mode 100644
index 000000000..ba0028529
--- /dev/null
+++ b/packages/open-next/src/wrappers/aws-lambda.ts
@@ -0,0 +1,34 @@
+import type {
+  APIGatewayProxyEvent,
+  APIGatewayProxyEventV2,
+  APIGatewayProxyResult,
+  APIGatewayProxyResultV2,
+  CloudFrontRequestEvent,
+  CloudFrontRequestResult,
+} from "aws-lambda";
+import type { Wrapper } from "types/open-next";
+
+import { WarmerEvent } from "../adapters/warmer-function";
+
+type AwsLambdaEvent =
+  | APIGatewayProxyEventV2
+  | CloudFrontRequestEvent
+  | APIGatewayProxyEvent
+  | WarmerEvent;
+
+type AwsLambdaReturn =
+  | APIGatewayProxyResultV2
+  | APIGatewayProxyResult
+  | CloudFrontRequestResult;
+
+const handler: Wrapper =
+  async (handler, converter) =>
+  async (event: AwsLambdaEvent): Promise<AwsLambdaReturn> => {
+    const internalEvent = await converter.convertFrom(event);
+
+    const response = await handler(internalEvent);
+
+    return converter.convertTo(response);
+  };
+
+export default handler;
diff --git a/packages/open-next/src/wrappers/cloudflare.ts b/packages/open-next/src/wrappers/cloudflare.ts
new file mode 100644
index 000000000..7d5db285b
--- /dev/null
+++ b/packages/open-next/src/wrappers/cloudflare.ts
@@ -0,0 +1,20 @@
+import type { InternalEvent, InternalResult, Wrapper } from "types/open-next";
+
+import { MiddlewareOutputEvent } from "../core/routingHandler";
+
+const handler: Wrapper<
+  InternalEvent,
+  InternalResult | ({ type: "middleware" } & MiddlewareOutputEvent)
+> =
+  async (handler, converter) =>
+  async (event: Request): Promise<Response> => {
+    const internalEvent = await converter.convertFrom(event);
+
+    const response = await handler(internalEvent);
+
+    const result: Response = converter.convertTo(response);
+
+    return result;
+  };
+
+export default handler;
diff --git a/packages/open-next/src/wrappers/node.ts b/packages/open-next/src/wrappers/node.ts
new file mode 100644
index 000000000..12f6639a6
--- /dev/null
+++ b/packages/open-next/src/wrappers/node.ts
@@ -0,0 +1,57 @@
+import { createServer } from "node:http";
+
+import { StreamCreator } from "http/index.js";
+import type { Wrapper } from "types/open-next";
+
+import { debug, error } from "../adapters/logger";
+
+const wrapper: Wrapper = async (handler, converter) => {
+  const server = createServer(async (req, res) => {
+    const internalEvent = await converter.convertFrom(req);
+    const _res: StreamCreator = {
+      writeHeaders: (prelude) => {
+        res.writeHead(prelude.statusCode, prelude.headers);
+        res.uncork();
+        return res;
+      },
+      onFinish: () => {
+        // Is it necessary to do something here?
+      },
+    };
+
+    await handler(internalEvent, _res);
+  });
+
+  await new Promise<void>((resolve) => {
+    server.on("listening", () => {
+      const cleanup = (code: number) => {
+        debug(`Closing server`);
+        server.close(() => {
+          debug(`Server closed`);
+          process.exit(code);
+        });
+      };
+      console.log(`Listening on port ${process.env.PORT ?? "3000"}`);
+      debug(`Open Next version: ${process.env.OPEN_NEXT_VERSION}`);
+
+      process.on("exit", (code) => cleanup(code));
+
+      process.on("SIGINT", () => cleanup(0));
+      process.on("SIGTERM", () => cleanup(0));
+
+      resolve();
+    });
+
+    server.listen(parseInt(process.env.PORT ?? "3000", 10));
+  });
+
+  server.on("error", (err) => {
+    error(err);
+  });
+
+  return () => {
+    server.close();
+  };
+};
+
+export default wrapper;
diff --git a/packages/open-next/tsconfig.json b/packages/open-next/tsconfig.json
index 6d8322954..c4c987fd4 100644
--- a/packages/open-next/tsconfig.json
+++ b/packages/open-next/tsconfig.json
@@ -5,6 +5,11 @@
     "module": "esnext",
     "lib": ["DOM", "ESNext"],
     "outDir": "./dist",
-    "allowSyntheticDefaultImports": true
+    "allowSyntheticDefaultImports": true,
+    "paths": {
+      "types/*": ["./src/types/*"],
+      "config/*": ["./src/adapters/config/*"],
+      "http/*": ["./src/http/*"],
+    }
   }
 }
