Skip to content

Commit

Permalink
Support @astrojs/[email protected] and above (#1340)
Browse files Browse the repository at this point in the history
  • Loading branch information
emmatown authored Oct 23, 2024
1 parent dccad1a commit 92fc874
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 23 deletions.
5 changes: 5 additions & 0 deletions .changeset/hip-trees-swim.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@keystatic/astro': patch
---

Support `@astrojs/[email protected]` and above
50 changes: 27 additions & 23 deletions packages/astro/src/api.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,34 @@ import type { APIContext } from 'astro';
import { parseString } from 'set-cookie-parser';

export function makeHandler(_config: APIRouteConfig) {
const handler = makeGenericAPIRouteHandler(
{
..._config,
clientId:
_config.clientId ??
tryOrUndefined(() => {
return import.meta.env.KEYSTATIC_GITHUB_CLIENT_ID;
}),
clientSecret:
_config.clientSecret ??
tryOrUndefined(() => {
return import.meta.env.KEYSTATIC_GITHUB_CLIENT_SECRET;
}),
secret:
_config.secret ??
tryOrUndefined(() => {
return import.meta.env.KEYSTATIC_SECRET;
}),
},
{
slugEnvName: 'PUBLIC_KEYSTATIC_GITHUB_APP_SLUG',
}
);
return async function keystaticAPIRoute(context: APIContext) {
const envVarsForCf = (context.locals as any)?.runtime?.env;
const handler = makeGenericAPIRouteHandler(
{
..._config,
clientId:
_config.clientId ??
envVarsForCf?.KEYSTATIC_GITHUB_CLIENT_ID ??
tryOrUndefined(() => {
return import.meta.env.KEYSTATIC_GITHUB_CLIENT_ID;
}),
clientSecret:
_config.clientSecret ??
envVarsForCf?.KEYSTATIC_GITHUB_CLIENT_SECRET ??
tryOrUndefined(() => {
return import.meta.env.KEYSTATIC_GITHUB_CLIENT_SECRET;
}),
secret:
_config.secret ??
envVarsForCf?.KEYSTATIC_SECRET ??
tryOrUndefined(() => {
return import.meta.env.KEYSTATIC_SECRET;
}),
},
{
slugEnvName: 'PUBLIC_KEYSTATIC_GITHUB_APP_SLUG',
}
);
const { body, headers, status } = await handler(context.request);
// all this stuff should be able to go away when astro is using a version of undici with getSetCookie
let headersInADifferentStructure = new Map<string, string[]>();
Expand Down

0 comments on commit 92fc874

Please sign in to comment.