Created
August 18, 2022 22:23
-
-
Save dector/7f52e3b91d6264fee0c3f702d2fce0b3 to your computer and use it in GitHub Desktop.
This file contains 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
/** @jsx h */ | |
import { h, json, jsx, serve } from "https://deno.land/x/sift@0.5.0/mod.ts"; | |
import { ssr } from "https://crux.land/nanossr@0.0.5"; | |
const App = () => ( | |
<div> | |
<h1>Hello world!</h1> | |
</div> | |
); | |
const NotFound = () => ( | |
<div> | |
<h1>Page not found</h1> | |
</div> | |
); | |
const Hello = (props) => ( | |
<div class={`bg-white flex h-screen`}> | |
<h1 class={`text-5xl text-gray-900 m-auto mt-20`}> | |
Hello {props.name}! | |
</h1> | |
</div> | |
); | |
serve({ | |
"/": () => jsx(<App />), | |
"/api": () => json({ message: "Hello world" }), | |
"/hello": (req) => { | |
const url = new URL(req.url); | |
const name = url.searchParams.get("name") ?? "world"; | |
console.log(`Name: ${name}`); | |
return ssr(() => <Hello name={name} />); | |
}, | |
404: () => jsx(<NotFound />, { status: 404 }), | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment