Created
March 27, 2024 17:44
-
-
Save itsMapleLeaf/94ff402d87c6c66b087db4edb39d35b4 to your computer and use it in GitHub Desktop.
more readable custom remix vite server
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 { createRequestHandler } from "@remix-run/express" | |
import express from "express" | |
const app = express() | |
let build | |
if (process.env.NODE_ENV === "production") { | |
build = await import("./build/server/index.js") | |
app.use(express.static("build/client")) | |
} else { | |
const vite = await import("vite") | |
const viteDevServer = await vite.createServer({ | |
server: { middlewareMode: true }, | |
}) | |
build = () => viteDevServer.ssrLoadModule("virtual:remix/server-build") | |
app.use(viteDevServer.middlewares) | |
} | |
app.all("*", createRequestHandler({ build })) | |
app.listen(3000, () => { | |
console.log("App listening on http://localhost:3000") | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment