Skip to content

Instantly share code, notes, and snippets.

@hashrock hashrock/server.tsx

Created Oct 8, 2019
Embed
What would you like to do?
One file server with deno
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 comment has been minimized.

Copy link

Soremwar commented Oct 13, 2019

Impressive, but not working on Deno v0.20

@hashrock

This comment has been minimized.

Copy link
Owner Author

hashrock commented Oct 15, 2019

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