mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-25 23:22:02 +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 stat = statSync(fullPath)
|
||||
|
||||
assets[id] = {
|
||||
assets['/' + id] = {
|
||||
type,
|
||||
etag,
|
||||
mtime: stat.mtime.toJSON(),
|
||||
|
@ -1,4 +1,5 @@
|
||||
import { createError } from 'h3'
|
||||
import { withoutTrailingSlash, withLeadingSlash, parseURL } from 'ufo'
|
||||
// @ts-ignore
|
||||
import { getAsset, readAsset } from '~static'
|
||||
|
||||
@ -12,15 +13,18 @@ export default async function serveStatic(req, res) {
|
||||
return
|
||||
}
|
||||
|
||||
let id = req.url.split('?')[0]
|
||||
if (id.startsWith('/')) {
|
||||
id = id.substr(1)
|
||||
}
|
||||
if (id.endsWith('/')) {
|
||||
id = id.substr(0, id.length - 1)
|
||||
}
|
||||
let id = withLeadingSlash(withoutTrailingSlash(parseURL(req.url).pathname))
|
||||
let asset = getAsset(id)
|
||||
|
||||
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 (id.startsWith(PUBLIC_PATH)) {
|
||||
|
Loading…
Reference in New Issue
Block a user