Skip to content

Instantly share code, notes, and snippets.

@hashrock hashrock/server.tsx

Created Oct 8, 2019
What would you like to do?
One file server with deno
import { serve } from "";
import React from "";
import ReactDOMServer from "";
const s = serve(":8000");
const hello: string = "Hello"
const View = (props) =>
<div className="deno">{hello}, {props.msg}</div>;
window.onload = async () => {
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 });

This comment has been minimized.

Copy link

Soremwar commented Oct 13, 2019

Impressive, but not working on Deno v0.20


This comment has been minimized.

Copy link
Owner Author

hashrock commented Oct 15, 2019

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
You can’t perform that action at this time.