Created
October 8, 2019 08:09
-
-
Save hashrock/3929319391526221bb761f521e35cdaa to your computer and use it in GitHub Desktop.
One file server with deno
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
import { serve } from "https://deno.land/std@v0.19.0/http/server.ts"; | |
import React from "https://dev.jspm.io/react"; | |
import ReactDOMServer from "https://dev.jspm.io/react-dom/server"; | |
const s = serve(":8000"); | |
const hello: string = "Hello" | |
const View = (props) => | |
<div className="deno">{hello}, {props.msg}</div>; | |
window.onload = async () => { | |
console.log("http://localhost:8000/"); | |
for await (const req of s) { | |
const matches = req.url.match(/\/?name=(.+)/) | |
const name = matches && matches[1] | |
const str = ReactDOMServer.renderToString(<View msg={name ? name : "None" } />); | |
const body = new TextEncoder().encode(str); | |
req.respond({ body }); | |
} | |
}; |
@Soremwar
This is tested with v0.20.0 on Ubuntu(WSL).
The Windows version of deno doesn't seem to work.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Impressive, but not working on Deno v0.20