0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2024-12-23 21:53:55 -05:00
astro/packages/integrations/deno/src/server.ts

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

52 lines
1.1 KiB
TypeScript
Raw Normal View History

import './shim.js';
import type { SSRManifest } from 'astro';
import { App } from 'astro/app';
// @ts-ignore
2022-03-30 07:43:13 -05:00
import { Server } from 'https://deno.land/std@0.132.0/http/server.ts';
interface Options {
port?: number;
hostname?: string;
start?: boolean;
}
let _server: Server | undefined = undefined;
let _startPromise: Promise<void> | undefined = undefined;
export function start(manifest: SSRManifest, options: Options) {
2022-03-30 07:43:13 -05:00
if (options.start === false) {
return;
}
const app = new App(manifest);
const handler = async (request: Request) => {
const response = await app.render(request);
return response;
};
_server = new Server({
2022-03-30 07:43:13 -05:00
port: options.port ?? 8085,
hostname: options.hostname ?? '0.0.0.0',
handler,
//onError: options.onError,
});
2022-03-30 07:43:13 -05:00
_startPromise = _server.listenAndServe();
}
export function createExports(manifest: SSRManifest) {
const app = new App(manifest);
return {
async stop() {
2022-03-30 07:43:13 -05:00
if (_server) {
_server.close();
}
await Promise.resolve(_startPromise);
},
async handle(request: Request) {
return app.render(request);
2022-03-30 07:43:13 -05:00
},
};
}