summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Fred K. Schott <fkschott@gmail.com> 2022-02-24 12:39:41 -0800
committerGravatar GitHub <noreply@github.com> 2022-02-24 14:39:41 -0600
commita0fc5cb5ff0003e9bb4b54cbf98035b1e0a6b113 (patch)
treee608293d1c595b99aad9cfa6b955822ae460a862
parent2e5c3b512638bf06c7eb896fcf5cd8179fe91ca8 (diff)
downloadastro-a0fc5cb5ff0003e9bb4b54cbf98035b1e0a6b113.tar.gz
astro-a0fc5cb5ff0003e9bb4b54cbf98035b1e0a6b113.tar.zst
astro-a0fc5cb5ff0003e9bb4b54cbf98035b1e0a6b113.zip
ensure utf8 encoding when serving html (#2654)
* ensure utf8 encoding on servers * Create spicy-tomatoes-act.md * Update spicy-tomatoes-act.md Co-authored-by: Nate Moore <natemoo-re@users.noreply.github.com>
-rw-r--r--.changeset/spicy-tomatoes-act.md5
-rw-r--r--examples/ssr/server/server.mjs3
-rw-r--r--packages/astro/src/vite-plugin-astro-server/index.ts5
3 files changed, 9 insertions, 4 deletions
diff --git a/.changeset/spicy-tomatoes-act.md b/.changeset/spicy-tomatoes-act.md
new file mode 100644
index 000000000..f4af5e96c
--- /dev/null
+++ b/.changeset/spicy-tomatoes-act.md
@@ -0,0 +1,5 @@
+---
+"astro": patch
+---
+
+Fix an issue where utf8 encoding was skipped in the dev server.
diff --git a/examples/ssr/server/server.mjs b/examples/ssr/server/server.mjs
index bc495f5c6..b08bed209 100644
--- a/examples/ssr/server/server.mjs
+++ b/examples/ssr/server/server.mjs
@@ -18,7 +18,8 @@ async function handle(req, res) {
const html = await app.render(req, route);
res.writeHead(200, {
- 'Content-Type': 'text/html',
+ 'Content-Type': 'text/html; charset=utf-8',
+ 'Content-Length': Buffer.byteLength(html, 'utf-8'),
});
res.end(html);
} else if (/^\/api\//.test(req.url)) {
diff --git a/packages/astro/src/vite-plugin-astro-server/index.ts b/packages/astro/src/vite-plugin-astro-server/index.ts
index 929040679..2b510cee7 100644
--- a/packages/astro/src/vite-plugin-astro-server/index.ts
+++ b/packages/astro/src/vite-plugin-astro-server/index.ts
@@ -3,7 +3,6 @@ import type http from 'http';
import type { AstroConfig, ManifestData, RouteData } from '../@types/astro';
import { info, LogOptions } from '../core/logger.js';
import { createRouteManifest, matchRoute } from '../core/routing/index.js';
-import mime from 'mime';
import stripAnsi from 'strip-ansi';
import { createSafeError } from '../core/util.js';
import { ssr } from '../core/render/dev/index.js';
@@ -30,8 +29,8 @@ function removeViteHttpMiddleware(server: vite.Connect.Server) {
function writeHtmlResponse(res: http.ServerResponse, statusCode: number, html: string) {
res.writeHead(statusCode, {
- 'Content-Type': mime.getType('.html') as string,
- 'Content-Length': Buffer.byteLength(html, 'utf8'),
+ 'Content-Type': 'text/html; charset=utf-8',
+ 'Content-Length': Buffer.byteLength(html, 'utf-8'),
});
res.write(html);
res.end();