mirror of
https://github.com/nuxt/nuxt.git
synced 2025-02-18 06:31:27 +00:00
fix: static asset handling with leading slash
This commit is contained in:
parent
cc4a32c024
commit
fd0be27f0c
@ -19,7 +19,7 @@ export function staticAssets (context: SigmaContext) {
|
|||||||
const etag = createEtag(readFileSync(fullPath))
|
const etag = createEtag(readFileSync(fullPath))
|
||||||
const stat = statSync(fullPath)
|
const stat = statSync(fullPath)
|
||||||
|
|
||||||
assets[id] = {
|
assets['/' + id] = {
|
||||||
type,
|
type,
|
||||||
etag,
|
etag,
|
||||||
mtime: stat.mtime.toJSON(),
|
mtime: stat.mtime.toJSON(),
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import { createError } from 'h3'
|
import { createError } from 'h3'
|
||||||
|
import { withoutTrailingSlash, withLeadingSlash, parseURL } from 'ufo'
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
import { getAsset, readAsset } from '~static'
|
import { getAsset, readAsset } from '~static'
|
||||||
|
|
||||||
@ -12,15 +13,18 @@ export default async function serveStatic(req, res) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
let id = req.url.split('?')[0]
|
let id = withLeadingSlash(withoutTrailingSlash(parseURL(req.url).pathname))
|
||||||
if (id.startsWith('/')) {
|
let asset = getAsset(id)
|
||||||
id = id.substr(1)
|
|
||||||
}
|
|
||||||
if (id.endsWith('/')) {
|
|
||||||
id = id.substr(0, id.length - 1)
|
|
||||||
}
|
|
||||||
|
|
||||||
const asset = getAsset(id) || getAsset(id = id + '/index.html')
|
// Try index.html
|
||||||
|
if (!asset) {
|
||||||
|
const _id = id + '/index.html'
|
||||||
|
const _asset = getAsset(_id)
|
||||||
|
if (_asset) {
|
||||||
|
asset = _asset
|
||||||
|
id = _id
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!asset) {
|
if (!asset) {
|
||||||
if (id.startsWith(PUBLIC_PATH)) {
|
if (id.startsWith(PUBLIC_PATH)) {
|
||||||
|
Loading…
Reference in New Issue
Block a user