Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions packages/astro/src/core/app/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export type { RoutesList } from '../../types/astro.js';
export { App } from './app.js';
export { BaseApp, type RenderErrorOptions, type RenderOptions } from './base.js';
export { deserializeManifest, fromRoutingStrategy, toRoutingStrategy } from './common.js';
Expand Down
3 changes: 1 addition & 2 deletions packages/astro/src/vite-plugin-app/pipeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,7 @@ export class AstroServerPipeline extends Pipeline {
logger,
manifest,
settings,
}: Pick<AstroServerPipeline, 'loader' | 'logger' | 'manifest' | 'settings'>

}: Pick<AstroServerPipeline, 'loader' | 'logger' | 'manifest' | 'settings'>,
) {
const pipeline = new AstroServerPipeline(loader, logger, manifest, settings);
pipeline.routesList = manifestData;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/// <reference types="vite/client" />
import { joinPaths } from '@astrojs/internal-helpers/path';
import type { ExternalImageService } from 'astro';
import { baseService } from 'astro/assets';
Expand Down Expand Up @@ -25,7 +26,6 @@ const service: ExternalImageService = {
}

const imageEndpoint = joinPaths(
// @ts-expect-error Can't recognise import.meta.env
import.meta.env.BASE_URL,
'/cdn-cgi/image',
resizingParams.join(','),
Expand Down
39 changes: 20 additions & 19 deletions packages/integrations/cloudflare/src/entrypoints/server.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
import type { ExecutionContext, ExportedHandlerFetchHandler } from '@cloudflare/workers-types';
import type { SSRManifest } from 'astro';
/// <reference types="vite/client" />

import { App } from 'astro/app';
import { handle } from '../utils/handler.js';
import type { ExportedHandler } from '@cloudflare/workers-types';
import type { RouteInfo, SSRManifest } from 'astro';
import { App, type BaseApp, createConsoleLogger, DevApp, type RoutesList } from 'astro/app';
import { type Env, handle } from '../utils/handler.js';

type Env = {
[key: string]: unknown;
ASSETS: { fetch: (req: Request | string) => Promise<Response> };
};
export function createExports(manifest: SSRManifest, routes: RouteInfo[]) {
let app: BaseApp;

export function createExports(manifest: SSRManifest) {
const app = new App(manifest);

const fetch = async (
request: Parameters<ExportedHandlerFetchHandler>[0],
env: Env,
context: ExecutionContext,
) => {
return await handle(manifest, app, request, env, context);
if (import.meta.env.DEV) {
const routesList: RoutesList = { routes: routes.map((r: RouteInfo) => r.routeData) };
const logger = createConsoleLogger('debug');
app = new DevApp(manifest, true, logger, routesList);
} else {
app = new App(manifest);
}
return {
default: {
async fetch(request, env, ctx) {
return await handle(manifest, app, request, env, ctx);
},
} satisfies ExportedHandler<Env>,
};

return { default: { fetch } };
}
15 changes: 8 additions & 7 deletions packages/integrations/cloudflare/src/utils/handler.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
// @ts-expect-error - It is safe to expect the error here.
import { env as globalEnv } from 'cloudflare:workers';
import type {
Response as CfResponse,
CacheStorage as CloudflareCacheStorage,
ExecutionContext,
ExportedHandlerFetchHandler,
} from '@cloudflare/workers-types';
import type { SSRManifest } from 'astro';
import type { App } from 'astro/app';
import type { BaseApp } from 'astro/app';
import { setGetEnv } from 'astro/env/setup';
import { createGetEnv } from '../utils/env.js';

type Env = {
export type Env = {
[key: string]: unknown;
ASSETS: { fetch: (req: Request | string) => Promise<Response> };
ASSETS: { fetch: (req: Request | string) => Promise<CfResponse> };
};

setGetEnv(createGetEnv(globalEnv as Env));
Expand All @@ -36,11 +37,11 @@ declare global {

export async function handle(
manifest: SSRManifest,
app: App,
app: BaseApp,
request: Parameters<ExportedHandlerFetchHandler>[0],
env: Env,
context: ExecutionContext,
) {
): Promise<CfResponse> {
const { pathname } = new URL(request.url);
const bindingName = globalThis.__ASTRO_SESSION_BINDING_NAME;
// Assigning the KV binding to globalThis allows unstorage to access it for session storage.
Expand Down Expand Up @@ -90,7 +91,7 @@ export async function handle(
routeData,
locals,
prerenderedErrorPageFetch: async (url) => {
return env.ASSETS.fetch(url.replace(/\.html$/, ''));
return env.ASSETS.fetch(url.replace(/\.html$/, '')) as unknown as Response;
},
},
);
Expand All @@ -101,5 +102,5 @@ export async function handle(
}
}

return response;
return response as unknown as CfResponse;
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,5 @@ import { defineConfig } from 'astro/config';

export default defineConfig({
adapter: cloudflare({
workerEntryPoint: {
path: 'src/worker.ts',
}
}),
});
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { manifest } from "astro:serialized-manifest";
import { routes } from "astro:routes"
import { createExports } from "./worker";
import { createExports } from "@astrojs/cloudflare/entrypoints/server.js";

export default createExports(manifest, routes).default

This file was deleted.

70 changes: 70 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading