Skip to content

Instantly share code, notes, and snippets.

@itsMapleLeaf
Created March 27, 2024 17:44
Show Gist options
  • Save itsMapleLeaf/94ff402d87c6c66b087db4edb39d35b4 to your computer and use it in GitHub Desktop.
Save itsMapleLeaf/94ff402d87c6c66b087db4edb39d35b4 to your computer and use it in GitHub Desktop.
more readable custom remix vite server
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