Skip to content

Commit

Permalink
fix: basic mime type handling for prerendered pages in preview (#10851)
Browse files Browse the repository at this point in the history
  • Loading branch information
benmccann authored Oct 17, 2023
1 parent cf3af61 commit 0381fee
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 15 deletions.
5 changes: 5 additions & 0 deletions .changeset/brave-parrots-sleep.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/kit': patch
---

fix: basic mime type handling for prerendered pages in preview
5 changes: 5 additions & 0 deletions .changeset/clean-garlics-deny.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/kit': patch
---

chore: use just a single library (mrmime) for mime type handling
3 changes: 1 addition & 2 deletions packages/kit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"esm-env": "^1.0.0",
"kleur": "^4.1.5",
"magic-string": "^0.30.0",
"mime": "^3.0.0",
"mrmime": "^1.0.1",
"sade": "^1.8.1",
"set-cookie-parser": "^2.6.0",
"sirv": "^2.0.2",
Expand All @@ -28,7 +28,6 @@
"devDependencies": {
"@playwright/test": "1.30.0",
"@types/connect": "^3.4.35",
"@types/mime": "^3.0.1",
"@types/node": "^16.18.6",
"@types/sade": "^1.7.4",
"@types/set-cookie-parser": "^2.4.2",
Expand Down
4 changes: 2 additions & 2 deletions packages/kit/src/core/sync/create_manifest_data/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import fs from 'node:fs';
import path from 'node:path';
import colors from 'kleur';
import mime from 'mime';
import { lookup } from 'mrmime';
import { list_files, runtime_directory } from '../../utils.js';
import { posixify } from '../../../utils/filesystem.js';
import { parse_route_id } from '../../../utils/routing.js';
Expand Down Expand Up @@ -48,7 +48,7 @@ export function create_assets(config) {
return list_files(config.kit.files.assets).map((file) => ({
file,
size: fs.statSync(path.resolve(config.kit.files.assets, file)).size,
type: mime.getType(file)
type: lookup(file) || null
}));
}

Expand Down
3 changes: 2 additions & 1 deletion packages/kit/src/exports/vite/preview/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import fs from 'node:fs';
import { join } from 'node:path';
import { pathToFileURL } from 'node:url';
import { lookup } from 'mrmime';
import sirv from 'sirv';
import { loadEnv, normalizePath } from 'vite';
import { getRequest, setResponse } from '../../../exports/node/index.js';
Expand Down Expand Up @@ -141,7 +142,7 @@ export async function preview(vite, vite_config, svelte_config) {

if (prerendered) {
res.writeHead(200, {
'content-type': 'text/html',
'content-type': lookup(pathname) || 'text/html',
etag
});

Expand Down
14 changes: 4 additions & 10 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 0381fee

Please sign in to comment.