Skip to content

Commit

Permalink
fix: use publicDir & base for 'include your base in url' error message (
Browse files Browse the repository at this point in the history
#9841)

Co-authored-by: Florian Lefebvre <contact@florian-lefebvre.dev>
Co-authored-by: bluwy <bjornlu.dev@gmail.com>
  • Loading branch information
3 people authored Feb 1, 2024
1 parent 2f448a2 commit 27ea080
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/eight-windows-kiss.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"astro": patch
---

Makes the warning clearer when having a custom `base` and requesting a public URL without it
10 changes: 8 additions & 2 deletions packages/astro/src/vite-plugin-astro-server/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 27ea080

Please sign in to comment.