Skip to content

Instantly share code, notes, and snippets.

@colinhacks
Created September 14, 2023 20:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save colinhacks/46166ded4a78e4e74c36980400fd76c5 to your computer and use it in GitHub Desktop.
Save colinhacks/46166ded4a78e4e74c36980400fd76c5 to your computer and use it in GitHub Desktop.
CrappyNext.js
import { renderToString } from "react-dom/server";
const router = new Bun.FileSystemRouter({
style: "nextjs",
dir: "./pages",
});
Bun.serve({
port: 3000,
development: true,
async fetch(req, server) {
const url = new URL(req.url);
if (url.pathname === "/favicon.ico") return new Response("no favicon");
const route = router.match(url.pathname);
if (route) {
const Handler = require(route.filePath).default;
const html = renderToString(<Handler />);
return new Response(html, {
headers: {
"content-type": "text/html; charset=utf-8",
},
});
}
return new Response("Not found", { status: 404 });
},
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment