Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use publicDir & base for 'include your base in url' error message #9841

Merged
merged 6 commits into from
Feb 1, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.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
Loading