Skip to content

Commit

Permalink
chore: update to std 1.0
Browse files Browse the repository at this point in the history
Updates the version of the std library to 1.0.0. This required a change
to the Http Server that was used. The Standard Library removed the Http
Server, so this change-set now uses Deno.serve directly.
  • Loading branch information
irbull committed Nov 1, 2024
1 parent b25538c commit 526e311
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 14 deletions.
5 changes: 2 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const SHIM = `globalThis.process = {
env: Deno.env.toObject(),
};`;

const STD_VERSION = `0.224.0`;
const STD_VERSION = `1.0`;
// REF: https://github.com/denoland/deno/tree/main/ext/node/polyfills
const COMPATIBLE_NODE_MODULES = [
"assert",
Expand Down Expand Up @@ -71,8 +71,7 @@ const COMPATIBLE_NODE_MODULES = [
// replaced with the Deno-specific contents listed below.
const DENO_IMPORTS_SHIM = `@deno/astro-adapter/__deno_imports.ts`;
const DENO_IMPORTS =
`export { Server } from "jsr:@std/http@${STD_VERSION}/server";
export { serveFile } from "jsr:@std/http@${STD_VERSION}/file-server";
`export { serveFile } from "jsr:@std/http@${STD_VERSION}/file-server";
export { fromFileUrl } from "jsr:@std/path@${STD_VERSION}";`;

export function getAdapter(args?: Options): AstroAdapter {
Expand Down
18 changes: 7 additions & 11 deletions src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import type { Options } from "./types";
import {
fromFileUrl,
serveFile,
Server,
} from "@deno/astro-adapter/__deno_imports.ts";

let _server: Server | undefined = undefined;
Expand Down Expand Up @@ -35,9 +34,9 @@ export function start(manifest: SSRManifest, options: Options) {

const clientRoot = new URL("../client/", import.meta.url);
const app = new App(manifest);
const handler = async (request: Request, connInfo: any) => {
const handler = async (request: Request, handlerInfo: any) => {
if (app.match(request)) {
let ip = connInfo?.remoteAddr?.hostname;
const ip = handlerInfo.remoteAddr?.hostname;
Reflect.set(request, Symbol.for("astro.clientAddress"), ip);
const response = await app.render(request);
if (app.setCookieHeaders) {
Expand Down Expand Up @@ -88,14 +87,11 @@ export function start(manifest: SSRManifest, options: Options) {
}
};

const port = options.port ?? 8085;
_server = new Server({
port,
hostname: options.hostname ?? "0.0.0.0",
handler,
});

_startPromise = Promise.resolve(_server.listenAndServe());
const port = options.port ?? 8085;
const hostname = options.hostname ?? "0.0.0.0";
_server = Deno.serve({ port, hostname }, handler);
_startPromise = _server.finished;
console.error(`Server running on port ${port}`);
}

Expand All @@ -104,7 +100,7 @@ export function createExports(manifest: SSRManifest, options: Options) {
return {
async stop() {
if (_server) {
_server.close();
_server.shutdown();
_server = undefined;
}
await Promise.resolve(_startPromise);
Expand Down

0 comments on commit 526e311

Please sign in to comment.