Skip to content

Commit

Permalink
feat(vite-plugin-nitro): handle web Response object in dev server plu…
Browse files Browse the repository at this point in the history
…gin (#1141)
  • Loading branch information
brandonroberts committed Jun 3, 2024
1 parent 4df4c29 commit a8b0f32
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions packages/vite-plugin-nitro/src/lib/plugins/dev-server-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import { Connect, Plugin, ViteDevServer } from 'vite';
import { resolve } from 'node:path';
import { readFileSync } from 'node:fs';
import { createEvent, sendWebResponse } from 'h3';

interface ServerOptions {
index?: string;
Expand Down Expand Up @@ -43,10 +44,20 @@ export function devServerPlugin(options: ServerOptions): Plugin {
const entryServer = (
await viteServer.ssrLoadModule('~analog/entry-server')
)['default'];
const result = await entryServer(req.originalUrl, template, {
req,
res,
});
const result: string | Response = await entryServer(
req.originalUrl,
template,
{
req,
res,
}
);

if (result instanceof Response) {
sendWebResponse(createEvent(req, res), result);
return;
}

res.setHeader('Content-Type', 'text/html');
res.end(result);
} catch (e) {
Expand Down

0 comments on commit a8b0f32

Please sign in to comment.