Vike - Nitro example repo issues #1105
Replies: 4 comments 6 replies
-
Have you seen https://vite-plugin-ssr.com/renderPage? |
Beta Was this translation helpful? Give feedback.
-
Yes, I now have this: `import { renderPage } from "vite-plugin-ssr/server"; export default defineEventHandler(async (event) => { if (headers) { send(event, body);
`
], I did have to build the project before it stopped giving me errors, Is that expected behaviour? |
Beta Was this translation helpful? Give feedback.
-
Currently the middleware suggested from the vite-plugin-ssr docs take over the nitro routes returns, so something needs extra configuration there |
Beta Was this translation helpful? Give feedback.
-
The issue here is that you are using import { renderPage } from "vike/server";
import { RenderResponse } from "nitropack";
export default defineRenderHandler(async (event) => {
useRuntimeConfig(event);
const pageContextInit = { urlOriginal: event.node.req.originalUrl! };
const pageContext = await renderPage(pageContextInit);
if (!pageContext.httpResponse) return null;
// `body` is the HTML of the page with a route matching pageContextInit.urlOriginal
const { body, statusCode, headers } = pageContext.httpResponse;
const response: RenderResponse = {
body,
statusCode,
headers: Object.fromEntries(headers),
statusMessage: "ok",
};
return response;
}); Then add a vike middleware into const isProduction = process.env.NODE_ENV === "production";
export default defineEventHandler(async (event) => {
useRuntimeConfig(event);
// Vite integration
if (!isProduction) {
// We instantiate Vite's development server and integrate its middleware to our server.
// ⚠️ We instantiate it only in development. (It isn't needed in production and it
// would unnecessarily bloat our production server.)
const vite = await import("vite");
const viteDevMiddleware = (
await vite.createServer({
root: ".",
server: { middlewareMode: true },
})
).middlewares;
return fromNodeMiddleware(viteDevMiddleware)(event);
}
}); Add config to import { defineNitroConfig } from "nitropack/config";
export default defineNitroConfig({
renderer: "./vike.ts",
}); The issue here is that when the MHR kicks in, Vite's WS server restarts and you get |
Beta Was this translation helpful? Give feedback.
-
As mentioned in the discord i'm trying to combine Vike with nitro as a backend to create something that works like Nuxt.
https://github.com/ThimoDEV/turbo-nitro-vike-example
The current issues I encounter:
Vike has an example because it adds itself as middleware for the server to handle things
Nitro has its own way of defining middleware:
`export default defineEventHandler((event: H3Event) => {
});`
I don't fully understand which part of the server side Vike is taking and which part is done by nitro. Do I have to disable things in Vike, or change how it behaves for the server?
https://github.com/danielroe/agent-conf-2023/tree/main
I did find this example repo by Daniel Roe where he made a first example nitro - react framework. Maybe it can help us
Beta Was this translation helpful? Give feedback.
All reactions