Last active
January 3, 2022 07:19
-
-
Save mayankchoubey/10a7159eff79b42aa3797f69ebbedadd to your computer and use it in GitHub Desktop.
Deno hello name using ETA templating
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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