Hattip adapter for Deno. It requires Deno version 1.35.0 or higher.
Assuming you have your Hattip handler defined in handler.ts, create an entry file like the following and run with deno run -A entry.ts:
import { createServeHandler } from "npm:@hattip/adapter-deno";
import handler from "./handler.ts";
Deno.serve(createServeHandler(handler));If you want to serve static files, you can use the serveDir function from std/http/file_server.ts. Assuming your static files are in the public directory, you can use the following:
import { createRequestHandler } from "npm:@hattip/adapter-deno";
import hattipHandler from "./handler.js";
import { serveDir } from "https://deno.land/std/http/file_server.ts";
const handler = createRequestHandler(hattipHandler);
Deno.serve(async (request, connInfo) => {
const staticResponse = await serveDir(request, { fsRoot: "./public" });
if (staticResponse.status !== 404) {
return staticResponse;
}
return handler(request, connInfo);
});contex.platform.info is a Deno.ServeHandlerInfo object.
Usage of ctx.env() function requires --allow-env flag.