Skip to content

Instantly share code, notes, and snippets.

@mayankchoubey
Last active January 3, 2022 07:19
Show Gist options
  • Save mayankchoubey/10a7159eff79b42aa3797f69ebbedadd to your computer and use it in GitHub Desktop.
Save mayankchoubey/10a7159eff79b42aa3797f69ebbedadd to your computer and use it in GitHub Desktop.
Deno hello name using ETA templating
import * as Eta from "https://deno.land/x/eta/mod.ts";
import { serve } from "https://deno.land/std/http/mod.ts";
Eta.configure({ views: "./" });
const getName = (u: URL) => u.searchParams.get("name") || "James Bond 007";
const reqHandler = async (req: Request) => {
try {
const u = new URL(req.url);
switch (u.pathname) {
case "/":
return new Response(
await Eta.renderFile("index.eta", { name: await getName(u) }) as string,
{
headers: {
"content-type": "text/html",
},
},
);
break;
}
return new Response(null, { status: 404 });
} catch (e) {
console.log(e);
}
return new Response(null, { status: 500 });
};
serve(reqHandler, { port: 8080 });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment