From 12f1fe44f00ee8e4081f86fc7015b14c8501c0b7 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Thu, 27 Jun 2024 00:50:34 -0700 Subject: [PATCH] chore: fix playground SSR (#12195) --- playgrounds/demo/server.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/playgrounds/demo/server.js b/playgrounds/demo/server.js index cf2a6b2ab5..82a75e70e7 100644 --- a/playgrounds/demo/server.js +++ b/playgrounds/demo/server.js @@ -1,3 +1,4 @@ +// @ts-check import fs from 'node:fs'; import path from 'node:path'; import { fileURLToPath } from 'node:url'; @@ -22,7 +23,10 @@ async function createServer() { app.use('*', async (req, res) => { if (req.originalUrl !== '/') { - res.sendFile(path.resolve('./dist' + req.originalUrl)); + res.writeHead(200, { + 'Content-Type': 'application/javascript' + }); + res.end(fs.createReadStream(path.resolve('./dist' + req.originalUrl))); return; } @@ -34,7 +38,7 @@ async function createServer() { .replace(``, appHtml) .replace(``, headHtml); - res.end(html); + res.writeHead(200, { 'Content-Type': 'text/html' }).end(html); }); return { app, vite };