@@ -7,7 +7,7 @@ async function ensureEsbuildInitialized() {
|
||||
if (esbuildInitialized === false) {
|
||||
if (Deno.run === undefined) {
|
||||
esbuildInitialized = esbuild.initialize({
|
||||
wasmURL: "https://unpkg.com/esbuild-wasm@0.14.39/esbuild.wasm",
|
||||
wasmURL: "https://unpkg.com/esbuild-wasm@0.14.51/esbuild.wasm",
|
||||
worker: false,
|
||||
});
|
||||
} else {
|
||||
|
||||
@@ -2,10 +2,10 @@ import {
|
||||
ConnInfo,
|
||||
extname,
|
||||
fromFileUrl,
|
||||
mediaTypeLookup,
|
||||
RequestHandler,
|
||||
router,
|
||||
toFileUrl,
|
||||
typeByExtension,
|
||||
walk,
|
||||
} from "./deps.ts";
|
||||
import { h } from "preact";
|
||||
@@ -224,7 +224,7 @@ export class ServerContext {
|
||||
const localUrl = toFileUrl(entry.path);
|
||||
const path = localUrl.href.substring(staticFolder.href.length);
|
||||
const stat = await Deno.stat(localUrl);
|
||||
const contentType = mediaTypeLookup(extname(path)) ??
|
||||
const contentType = typeByExtension(extname(path)) ??
|
||||
"application/octet-stream";
|
||||
const etag = await crypto.subtle.digest(
|
||||
"SHA-1",
|
||||
@@ -559,7 +559,7 @@ export class ServerContext {
|
||||
"Cache-Control": "public, max-age=604800, immutable",
|
||||
});
|
||||
|
||||
const contentType = mediaTypeLookup(path);
|
||||
const contentType = typeByExtension(extname(path));
|
||||
if (contentType) {
|
||||
headers.set("Content-Type", contentType);
|
||||
}
|
||||
|
||||
+11
-11
@@ -3,28 +3,28 @@ export {
|
||||
extname,
|
||||
fromFileUrl,
|
||||
toFileUrl,
|
||||
} from "https://deno.land/std@0.128.0/path/mod.ts";
|
||||
export { walk } from "https://deno.land/std@0.128.0/fs/walk.ts";
|
||||
export { serve } from "https://deno.land/std@0.128.0/http/server.ts";
|
||||
} from "https://deno.land/std@0.150.0/path/mod.ts";
|
||||
export { walk } from "https://deno.land/std@0.150.0/fs/walk.ts";
|
||||
export { serve } from "https://deno.land/std@0.150.0/http/server.ts";
|
||||
export type {
|
||||
ConnInfo,
|
||||
Handler as RequestHandler,
|
||||
ServeInit,
|
||||
} from "https://deno.land/std@0.128.0/http/server.ts";
|
||||
} from "https://deno.land/std@0.150.0/http/server.ts";
|
||||
export {
|
||||
typeByExtension,
|
||||
} from "https://deno.land/std@0.150.0/media_types/mod.ts";
|
||||
|
||||
// -- router --
|
||||
export * as router from "https://crux.land/router@0.0.11";
|
||||
|
||||
// -- media types --
|
||||
export { lookup as mediaTypeLookup } from "https://deno.land/x/media_types@v2.10.2/mod.ts";
|
||||
|
||||
// -- esbuild --
|
||||
// @deno-types="https://deno.land/x/esbuild@v0.14.39/mod.d.ts"
|
||||
import * as esbuildWasm from "https://unpkg.com/esbuild-wasm@0.14.39/esm/browser.js";
|
||||
import * as esbuildNative from "https://deno.land/x/esbuild@v0.14.39/mod.js";
|
||||
// @deno-types="https://deno.land/x/esbuild@v0.14.51/mod.d.ts"
|
||||
import * as esbuildWasm from "https://deno.land/x/esbuild@v0.14.51/wasm.js";
|
||||
import * as esbuildNative from "https://deno.land/x/esbuild@v0.14.51/mod.js";
|
||||
// @ts-ignore trust me
|
||||
const esbuild: typeof esbuildWasm = Deno.run === undefined
|
||||
? esbuildWasm
|
||||
: esbuildNative;
|
||||
export { esbuild, esbuildWasm as esbuildTypes };
|
||||
export { denoPlugin } from "https://deno.land/x/esbuild_deno_loader@0.5.0/mod.ts";
|
||||
export { denoPlugin } from "https://deno.land/x/esbuild_deno_loader@0.5.2/mod.ts";
|
||||
|
||||
@@ -50,10 +50,5 @@ export async function start(
|
||||
opts: StartOptions = {},
|
||||
) {
|
||||
const ctx = await ServerContext.fromManifest(routes, opts);
|
||||
console.log(
|
||||
`Server listening on http://${opts?.hostname ?? "localhost"}:${
|
||||
opts?.port ?? 8000
|
||||
}`,
|
||||
);
|
||||
await serve(ctx.handler(), opts);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user