Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/serious-mayflies-greet.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"astro-sst": major
---

Adds support for Astro 6.0

Support for Astro 5.0 is dropped, use v3 of astro-sst by pinning to `astro-sst@three`.
9 changes: 6 additions & 3 deletions packages/astro-sst/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
"bugs": "https://github.com/sst/astro-sst/issues",
"exports": {
".": "./dist/adapter.js",
"./entrypoint": "./dist/entrypoint.js",
"./entrypoint/buffer": "./dist/entrypoint/buffer.js",
"./entrypoint/stream": "./dist/entrypoint/stream.js",
"./build-meta": "./dist/lib/build-meta.js",
"./package.json": "./package.json"
},
Expand All @@ -37,12 +38,14 @@
"scripts": {
"build": "tsc"
},
"peerDependencies": {
"astro": "^6.0.0"
},
"dependencies": {
"set-cookie-parser": "^2.7.1"
},
"devDependencies": {
"@types/aws-lambda": "^8.10.146",
"@types/set-cookie-parser": "^2.4.10",
"astro": "^5.0.8"
"@types/set-cookie-parser": "^2.4.10"
}
}
9 changes: 4 additions & 5 deletions packages/astro-sst/src/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ export default function createIntegration(
): AstroIntegration {
debug("astroVersion", ASTRO_PACKAGE.version);

if (astroMajorVersion < 5) {
if (astroMajorVersion < 6) {
throw new Error(
"astro-sst requires Astro 5 or newer. Please upgrade your Astro app. Alternatively, use v2 of astro-sst by pinning to `astro-sst@two`."
"astro-sst requires Astro 6 or newer. Please upgrade your Astro app. Alternatively, use v3 of astro-sst by pinning to `astro-sst@three`."
);
}

Expand Down Expand Up @@ -64,9 +64,8 @@ export default function createIntegration(
BuildMeta.setBuildOutput(buildOutput);
setAdapter({
name: PACKAGE_NAME,
serverEntrypoint: `${PACKAGE_NAME}/entrypoint`,
args: { responseMode: entrypointParameters.responseMode },
exports: ["handler"],
entrypointResolution: "auto",
serverEntrypoint: `${PACKAGE_NAME}/entrypoint/${entrypointParameters.responseMode}`,
adapterFeatures: {
edgeMiddleware: false,
buildOutput: buildOutput,
Expand Down
200 changes: 0 additions & 200 deletions packages/astro-sst/src/entrypoint.ts

This file was deleted.

69 changes: 69 additions & 0 deletions packages/astro-sst/src/entrypoint/buffer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import { createApp } from "astro/app/entrypoint";
import type {
APIGatewayProxyEventV2,
CloudFrontRequestEvent,
} from "aws-lambda";
import fs from "fs/promises";
import { convertFrom, convertTo } from "../lib/event-mapper.js";
import { debug } from "../lib/logger.js";
import {
build404Url,
createRequest,
existsAsync,
} from "../lib/entrypoint-utils.js";

const app = createApp();

export async function handler(
event: APIGatewayProxyEventV2 | CloudFrontRequestEvent,
) {
debug("event", event);

const internalEvent = convertFrom(event);
let request = createRequest(internalEvent);
let routeData = app.match(request);
if (!routeData) {
// handle prerendered 404
if (await existsAsync("404.html")) {
return convertTo({
type: internalEvent.type,
response: new Response(await fs.readFile("404.html", "utf-8"), {
status: 404,
headers: {
"Content-Type": "text/html",
},
}),
});
}

// handle server-side 404
request = createRequest({
...internalEvent,
url: build404Url(internalEvent.url),
});
routeData = app.match(request);
if (!routeData) {
return convertTo({
type: internalEvent.type,
response: new Response("Not found", { status: 404 }),
});
}
}

// Process request
const response = await app.render(request, {
routeData,
clientAddress:
internalEvent.headers["x-forwarded-for"] || internalEvent.remoteAddress,
});

// Buffer response back to Cloudfront
const convertedResponse = await convertTo({
type: internalEvent.type,
response,
cookies: Array.from(app.setCookieHeaders(response)),
});

debug("response", convertedResponse);
return convertedResponse;
}
Loading