Created
September 14, 2023 20:52
-
-
Save colinhacks/46166ded4a78e4e74c36980400fd76c5 to your computer and use it in GitHub Desktop.
CrappyNext.js
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 { 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