mirror of
https://github.com/withastro/astro.git
synced 2025-01-22 10:31:53 -05:00
fix: use publicDir & base for 'include your base in url' error message (#9841)
Co-authored-by: Florian Lefebvre <contact@florian-lefebvre.dev> Co-authored-by: bluwy <bjornlu.dev@gmail.com>
This commit is contained in:
parent
2f448a27f2
commit
27ea080e24
2 changed files with 13 additions and 2 deletions
5
.changeset/eight-windows-kiss.md
Normal file
5
.changeset/eight-windows-kiss.md
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
"astro": patch
|
||||
---
|
||||
|
||||
Makes the warning clearer when having a custom `base` and requesting a public URL without it
|
|
@ -3,6 +3,8 @@ import type { AstroSettings } from '../@types/astro.js';
|
|||
|
||||
import { bold } from 'kleur/colors';
|
||||
import * as fs from 'node:fs';
|
||||
import path from 'node:path';
|
||||
import { appendForwardSlash } from '@astrojs/internal-helpers/path';
|
||||
import type { Logger } from '../core/logger/core.js';
|
||||
import notFoundTemplate, { subpathNotUsedTemplate } from '../template/4xx.js';
|
||||
import { writeHtmlResponse } from './response.js';
|
||||
|
@ -52,11 +54,15 @@ export function baseMiddleware(
|
|||
const publicPath = new URL('.' + req.url, config.publicDir);
|
||||
fs.stat(publicPath, (_err, stats) => {
|
||||
if (stats) {
|
||||
const expectedLocation = new URL('.' + url, devRootURL).pathname;
|
||||
const publicDir = appendForwardSlash(
|
||||
path.posix.relative(config.root.pathname, config.publicDir.pathname)
|
||||
);
|
||||
const expectedLocation = new URL(devRootURL.pathname + url, devRootURL).pathname;
|
||||
|
||||
logger.error(
|
||||
'router',
|
||||
`Request URLs for ${bold(
|
||||
'public/'
|
||||
publicDir
|
||||
)} assets must also include your base. "${expectedLocation}" expected, but received "${url}".`
|
||||
);
|
||||
const html = subpathNotUsedTemplate(devRoot, pathname);
|
||||
|
|
Loading…
Reference in a new issue