Skip to content

Commit

Permalink
add await to createStandaloneHandler
Browse files Browse the repository at this point in the history
  • Loading branch information
Neville Mehta authored and Neville Mehta committed Jul 19, 2024
1 parent 2e50428 commit 0c70ad9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
12 changes: 6 additions & 6 deletions packages/integrations/node/src/preview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@ import { fileURLToPath } from 'node:url';
import type { CreatePreviewServer } from 'astro';
import { AstroError } from 'astro/errors';
import { logListeningOn } from './log-listening-on.js';
import type { createExports } from './server.js';
// import type { createExports } from './server.js';
import { createServer } from './standalone.js';

type ServerModule = ReturnType<typeof createExports>;
type MaybeServerModule = Partial<ServerModule>;
// type ServerModule = Promise<ReturnType<typeof createExports>>;
// type MaybeServerModule = Partial<ServerModule>;

const createPreviewServer: CreatePreviewServer = async function (preview) {
let ssrHandler: ServerModule['handler'];
let options: ServerModule['options'];
let ssrHandler: any;
let options: any;
try {
process.env.ASTRO_NODE_AUTOSTART = 'disabled';
const ssrModule: MaybeServerModule = await import(preview.serverEntrypoint.toString());
const ssrModule: any = await import(preview.serverEntrypoint.toString());
if (typeof ssrModule.handler === 'function') {
ssrHandler = ssrModule.handler;
options = ssrModule.options!;
Expand Down
6 changes: 4 additions & 2 deletions packages/integrations/node/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@ await import('astro/env/setup')
.catch(() => {});

applyPolyfills();
export function createExports(manifest: SSRManifest, options: Options) {
export async function createExports(manifest: SSRManifest, options: Options) {
const app = new NodeApp(manifest);
options.trailingSlash = manifest.trailingSlash;
const middleware = createMiddleware(app);
const standaloneHandler = await createStandaloneHandler(app, options);
return {
options: options,
handler:
options.mode === 'middleware' ? createMiddleware(app) : createStandaloneHandler(app, options),
options.mode === 'middleware' ? middleware : standaloneHandler,
startServer: () => startServer(app, options),
};
}
Expand Down

0 comments on commit 0c70ad9

Please sign in to comment.