Skip to content

Commit

Permalink
Use experimental release
Browse files Browse the repository at this point in the history
  • Loading branch information
ascorbic committed Dec 5, 2024
1 parent 6373fca commit 33bec6c
Show file tree
Hide file tree
Showing 53 changed files with 184 additions and 465 deletions.
4 changes: 2 additions & 2 deletions packages/cloudflare/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@
"wrangler": "^3.91.0"
},
"peerDependencies": {
"astro": "^5.0.0"
"astro": "0.0.0-sessions-20241205163205"
},
"devDependencies": {
"@astrojs/test-utils": "workspace:*",
"astro": "^5.0.0",
"astro": "0.0.0-sessions-20241205163205",
"astro-scripts": "workspace:*",
"cheerio": "1.0.0",
"execa": "^8.0.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"private": true,
"dependencies": {
"@astrojs/cloudflare": "workspace:*",
"astro": "0.0.0-sessions-20241128134018"
"astro": "0.0.0-sessions-20241205163205"
},
"devDependencies": {
"wrangler": "^3.84.0"
Expand Down
2 changes: 1 addition & 1 deletion packages/cloudflare/test/fixtures/astro-env/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"private": true,
"dependencies": {
"@astrojs/cloudflare": "workspace:*",
"astro": "0.0.0-sessions-20241128134018"
"astro": "0.0.0-sessions-20241205163205"
},
"devDependencies": {
"wrangler": "^3.84.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
"private": true,
"dependencies": {
"@astrojs/cloudflare": "workspace:*",
"astro": "0.0.0-sessions-20241128134018"
"astro": "0.0.0-sessions-20241205163205"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
"private": true,
"dependencies": {
"@astrojs/cloudflare": "workspace:*",
"astro": "0.0.0-sessions-20241128134018"
"astro": "0.0.0-sessions-20241205163205"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
"private": true,
"dependencies": {
"@astrojs/cloudflare": "workspace:*",
"astro": "0.0.0-sessions-20241128134018"
"astro": "0.0.0-sessions-20241205163205"
}
}
2 changes: 1 addition & 1 deletion packages/cloudflare/test/fixtures/no-output/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
"private": true,
"dependencies": {
"@astrojs/cloudflare": "workspace:*",
"astro": "0.0.0-sessions-20241128134018"
"astro": "0.0.0-sessions-20241205163205"
}
}
2 changes: 1 addition & 1 deletion packages/cloudflare/test/fixtures/routes-json/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
"private": true,
"dependencies": {
"@astrojs/cloudflare": "workspace:*",
"astro": "0.0.0-sessions-20241128134018"
"astro": "0.0.0-sessions-20241205163205"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"dependencies": {
"@astrojs/cloudflare": "workspace:*",
"@astrojs/solid-js": "^4.4.2",
"astro": "0.0.0-sessions-20241128134018",
"astro": "0.0.0-sessions-20241205163205",
"solid-js": "^1.9.3"
}
}
4 changes: 2 additions & 2 deletions packages/cloudflare/test/fixtures/with-svelte/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"dependencies": {
"@astrojs/cloudflare": "workspace:*",
"@astrojs/svelte": "^7.0.1",
"astro": "^5.0.0",
"astro": "0.0.0-sessions-20241205163205",
"svelte": "^5.6.0"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
"private": true,
"dependencies": {
"@astrojs/cloudflare": "workspace:*",
"astro": "0.0.0-sessions-20241128134018"
"astro": "0.0.0-sessions-20241205163205"
}
}
4 changes: 2 additions & 2 deletions packages/netlify/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,14 @@
"vite": "^6.0.2"
},
"peerDependencies": {
"astro": "^5.0.0"
"astro": "0.0.0-sessions-20241205163205"
},
"devDependencies": {
"@astrojs/test-utils": "workspace:*",
"@netlify/edge-functions": "^2.11.1",
"@netlify/edge-handler-types": "^0.34.1",
"@types/node": "^22.10.0",
"astro": "0.0.0-sessions-20241128172109",
"astro": "0.0.0-sessions-20241205163205",
"astro-scripts": "workspace:*",
"cheerio": "1.0.0",
"execa": "^8.0.1",
Expand Down
24 changes: 5 additions & 19 deletions packages/netlify/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -280,22 +280,18 @@ export default function netlifyIntegration(

async function writeMiddleware(entrypoint: URL) {
await mkdir(middlewareOutputDir(), { recursive: true });
console.log(_config.experimental?.session);
await writeFile(
new URL('./entry.mjs', middlewareOutputDir()),
/* ts */ `
import { onRequest, getManifest } from "${fileURLToPath(entrypoint).replaceAll('\\', '/')}";
import { onRequest } from "${fileURLToPath(entrypoint).replaceAll('\\', '/')}";
import { createContext, trySerializeLocals } from 'astro/middleware';
export default async (request, context) => {
const manifest = await getManifest();
const ctx = createContext({
request,
params: {},
manifest
params: {}
});
ctx.locals.netlify = { context }
ctx.locals = { netlify: { context } }
// https://docs.netlify.com/edge-functions/api/#return-a-rewrite
ctx.rewrite = (target) => {
if(target instanceof Request) {
Expand All @@ -317,10 +313,6 @@ export default function netlifyIntegration(
};
const next = () => {
const { netlify, ...otherLocals } = ctx.locals;
const data = Reflect.get(ctx.session, "data");
if(data) {
request.headers.set("x-astro-session", trySerializeLocals(data));
}
request.headers.set("x-astro-locals", trySerializeLocals(otherLocals));
request.headers.set("x-astro-middleware-secret", "${middlewareSecret}");
return context.next();
Expand Down Expand Up @@ -349,14 +341,6 @@ export default function netlifyIntegration(
path: args.path,
external: true,
}));
build.onResolve({ filter: /^@astro-session-driver$/ }, async (args) => {
const resolved = await build.resolve('unstorage/drivers/netlify-blobs', {
kind: 'import-statement',
resolveDir: args.resolveDir,
});
console.log(resolved);
return resolved;
});
},
},
],
Expand Down Expand Up @@ -390,6 +374,8 @@ export default function netlifyIntegration(
account: parseBase64JSON('x-nf-account-info') ?? {
id: 'mock-netlify-account-id',
},
// TODO: this has type conflicts with @netlify/functions ^2.8.1
// @ts-expect-error: this has type conflicts with @netlify/functions ^2.8.1
deploy: {
id:
typeof req.headers['x-nf-deploy-id'] === 'string'
Expand Down
19 changes: 5 additions & 14 deletions packages/netlify/src/ssr-function.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,30 +32,21 @@ export const createExports = (manifest: SSRManifest, { middlewareSecret }: Args)

Reflect.set(request, clientAddressSymbol, context.ip);
let locals: Record<string, unknown> = {};
let initialSessionData: Record<string, unknown> = {};

const astroLocalsHeader = request.headers.get('x-astro-locals');
const astroSessionHeader = request.headers.get('x-astro-session');
const middlewareSecretHeader = request.headers.get('x-astro-middleware-secret');
// hide the secret from the rest of user and library code
request.headers.delete('x-astro-middleware-secret');
if (astroLocalsHeader || astroSessionHeader) {
if (astroLocalsHeader) {
if (middlewareSecretHeader !== middlewareSecret) {
return new Response('Forbidden', { status: 403 });
}

if (astroLocalsHeader) {
locals = JSON.parse(astroLocalsHeader);
}
if (astroSessionHeader) {
console.log('astroSessionHeader', astroSessionHeader);
initialSessionData = JSON.parse(astroSessionHeader);
}
// hide the secret from the rest of user and library code
request.headers.delete('x-astro-middleware-secret');
locals = JSON.parse(astroLocalsHeader);
}

locals.netlify = { context };

const response = await app.render(request, { routeData, locals, initialSessionData });
const response = await app.render(request, { routeData, locals });

if (app.setCookieHeaders) {
for (const setCookieHeader of app.setCookieHeaders(response)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"@astrojs/netlify": "workspace:*"
},
"devDependencies": {
"astro": "0.0.0-sessions-20241128172109"
"astro": "0.0.0-sessions-20241205163205"
},
"scripts": {
"build": "astro build",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
},
"dependencies": {
"@astrojs/netlify": "workspace:*",
"astro": "^5.0.0"
"astro": "0.0.0-sessions-20241205163205"
}
}
4 changes: 2 additions & 2 deletions packages/node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@
"server-destroy": "^1.0.1"
},
"peerDependencies": {
"astro": "^5.0.0"
"astro": "0.0.0-sessions-20241205163205"
},
"devDependencies": {
"@astrojs/test-utils": "workspace:*",
"@types/node": "^22.10.0",
"@types/send": "^0.17.4",
"@types/server-destroy": "^1.0.4",
"astro": "^5.0.0",
"astro": "0.0.0-sessions-20241205163205",
"astro-scripts": "workspace:*",
"cheerio": "1.0.0",
"express": "^4.21.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/node/test/fixtures/api-route/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "0.0.0",
"private": true,
"dependencies": {
"astro": "0.0.0-sessions-20241128134018",
"astro": "0.0.0-sessions-20241205163205",
"@astrojs/node": "workspace:*"
}
}
2 changes: 1 addition & 1 deletion packages/node/test/fixtures/bad-urls/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "0.0.0",
"private": true,
"dependencies": {
"astro": "0.0.0-sessions-20241128134018",
"astro": "0.0.0-sessions-20241205163205",
"@astrojs/node": "workspace:*"
}
}
2 changes: 1 addition & 1 deletion packages/node/test/fixtures/encoded/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "0.0.0",
"private": true,
"dependencies": {
"astro": "0.0.0-sessions-20241128134018",
"astro": "0.0.0-sessions-20241205163205",
"@astrojs/node": "workspace:*"
}
}
2 changes: 1 addition & 1 deletion packages/node/test/fixtures/errors/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "0.0.0",
"private": true,
"dependencies": {
"astro": "0.0.0-sessions-20241128134018",
"astro": "0.0.0-sessions-20241205163205",
"@astrojs/node": "workspace:*"
}
}
2 changes: 1 addition & 1 deletion packages/node/test/fixtures/headers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "0.0.0",
"private": true,
"dependencies": {
"astro": "0.0.0-sessions-20241128134018",
"astro": "0.0.0-sessions-20241205163205",
"@astrojs/node": "workspace:*"
}
}
2 changes: 1 addition & 1 deletion packages/node/test/fixtures/image/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "0.0.0",
"private": true,
"dependencies": {
"astro": "0.0.0-sessions-20241128134018",
"astro": "0.0.0-sessions-20241205163205",
"@astrojs/node": "workspace:*"
},
"peerDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/node/test/fixtures/locals/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "0.0.0",
"private": true,
"dependencies": {
"astro": "0.0.0-sessions-20241128134018",
"astro": "0.0.0-sessions-20241205163205",
"@astrojs/node": "workspace:*"
}
}
2 changes: 1 addition & 1 deletion packages/node/test/fixtures/node-middleware/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "0.0.0",
"private": true,
"dependencies": {
"astro": "0.0.0-sessions-20241128134018",
"astro": "0.0.0-sessions-20241205163205",
"@astrojs/node": "workspace:*"
}
}
2 changes: 1 addition & 1 deletion packages/node/test/fixtures/prerender-404-500/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"private": true,
"type": "module",
"dependencies": {
"astro": "0.0.0-sessions-20241128134018",
"astro": "0.0.0-sessions-20241205163205",
"@astrojs/node": "workspace:*"
}
}
2 changes: 1 addition & 1 deletion packages/node/test/fixtures/prerender/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "0.0.0",
"private": true,
"dependencies": {
"astro": "0.0.0-sessions-20241128134018",
"astro": "0.0.0-sessions-20241205163205",
"@astrojs/node": "workspace:*"
}
}
2 changes: 1 addition & 1 deletion packages/node/test/fixtures/preview-headers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "0.0.0",
"private": true,
"dependencies": {
"astro": "0.0.0-sessions-20241128134018",
"astro": "0.0.0-sessions-20241205163205",
"@astrojs/node": "workspace:*"
}
}
2 changes: 1 addition & 1 deletion packages/node/test/fixtures/session/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
"private": true,
"dependencies": {
"@astrojs/node": "workspace:*",
"astro": "0.0.0-sessions-20241128134018"
"astro": "0.0.0-sessions-20241205163205"
}
}
2 changes: 1 addition & 1 deletion packages/node/test/fixtures/trailing-slash/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "0.0.0",
"private": true,
"dependencies": {
"astro": "0.0.0-sessions-20241128134018",
"astro": "0.0.0-sessions-20241205163205",
"@astrojs/node": "workspace:*"
}
}
2 changes: 1 addition & 1 deletion packages/node/test/fixtures/url/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "0.0.0",
"private": true,
"dependencies": {
"astro": "0.0.0-sessions-20241128134018",
"astro": "0.0.0-sessions-20241205163205",
"@astrojs/node": "workspace:*"
}
}
Loading

0 comments on commit 33bec6c

Please sign in to comment.