Created
April 29, 2020 18:33
-
-
Save jeanlescure/803d21ebae79b97737895d663ffd2d1f to your computer and use it in GitHub Desktop.
React.js quick dev server on Deno minimal example
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 React from 'https://dev.jspm.io/react'; | |
export const App = () => { | |
return ( | |
<div>Hello React.js quick dev server with Deno example!</div> | |
); | |
}; |
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 { serve } from 'https://deno.land/std/http/server.ts'; | |
import React from 'https://dev.jspm.io/react'; | |
import ReactDOMServer from 'https://dev.jspm.io/react-dom/server'; | |
import { App } from './app.tsx'; | |
export const str = ReactDOMServer.renderToString(<App />); | |
const body = new TextEncoder().encode(str); | |
const server = serve(':8080'); | |
// To start this server simply run: deno ./server.tsx | |
window.onload = async () => { | |
console.log('Server started at: http://localhost:8080/'); | |
for await (const req of server) { | |
req.respond({ body }); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment