Skip to content

Commit e1d7109

Browse files
authored
fix: apply baseURL to production assets (#3734)
1 parent 3402cc7 commit e1d7109

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

src/build/plugins/public-assets.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import type { Nitro } from "nitro/types";
66
import type { PublicAsset } from "nitro/types";
77
import { relative, resolve } from "pathe";
88
import type { Plugin } from "rollup";
9-
import { withTrailingSlash } from "ufo";
9+
import { joinURL, withTrailingSlash } from "ufo";
1010
import { virtual } from "./virtual.ts";
1111

1212
const readAssetHandler: Record<
@@ -42,7 +42,10 @@ export function publicAssets(nitro: Nitro): Plugin {
4242
const etag = createEtag(assetData);
4343
const stat = await fsp.stat(fullPath);
4444

45-
const assetId = "/" + decodeURIComponent(id);
45+
const assetId = joinURL(
46+
nitro.options.baseURL,
47+
decodeURIComponent(id)
48+
);
4649

4750
let encoding;
4851
if (id.endsWith(".gz")) {
@@ -114,7 +117,9 @@ export function readAsset (id) {
114117
nitro.options.publicAssets
115118
.filter((dir) => !dir.fallthrough && dir.baseURL !== "/")
116119
.map((dir) => [
117-
withTrailingSlash(dir.baseURL),
120+
withTrailingSlash(
121+
joinURL(nitro.options.baseURL, dir.baseURL || "/")
122+
),
118123
{ maxAge: dir.maxAge },
119124
])
120125
);

src/presets/standard/preset.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ const standard = defineNitroPreset(
55
entry: "./standard/runtime/server",
66
serveStatic: false,
77
exportConditions: ["import", "default"],
8+
output: {
9+
publicDir: "{{ output.dir }}/public/{{ baseURL }}",
10+
},
811
commands: {
912
preview: "npx srvx --prod ./",
1013
},

0 commit comments

Comments
 (0)