fix(middleware): undo config's path to URL encoding (#8614)

* fix(middleware): undo config's path to URL encoding

* add changeset

* middleware-dev => "middleware space"
This commit is contained in:
Arsh 2023-09-21 11:05:33 +05:30 committed by GitHub
parent b4034aabea
commit 4398e92987
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
20 changed files with 14 additions and 9 deletions

View file

@ -0,0 +1,5 @@
---
'astro': patch
---
Fixed an issue where spaces and unicode characters in project path prevented middleware from running.

View file

@ -25,7 +25,7 @@ export function vitePluginMiddleware(
async resolveId(id) { async resolveId(id) {
if (id === MIDDLEWARE_MODULE_ID) { if (id === MIDDLEWARE_MODULE_ID) {
const middlewareId = await this.resolve( const middlewareId = await this.resolve(
`${opts.settings.config.srcDir.pathname}/${MIDDLEWARE_PATH_SEGMENT_NAME}` `${decodeURI(opts.settings.config.srcDir.pathname)}${MIDDLEWARE_PATH_SEGMENT_NAME}`
); );
if (middlewareId) { if (middlewareId) {
resolvedMiddlewareId = middlewareId.id; resolvedMiddlewareId = middlewareId.id;

View file

@ -12,7 +12,7 @@ export async function loadMiddleware(
srcDir: AstroSettings['config']['srcDir'] srcDir: AstroSettings['config']['srcDir']
) { ) {
// can't use node Node.js builtins // can't use node Node.js builtins
let middlewarePath = srcDir.pathname + '/' + MIDDLEWARE_PATH_SEGMENT_NAME; let middlewarePath = `${decodeURI(srcDir.pathname)}${MIDDLEWARE_PATH_SEGMENT_NAME}`;
try { try {
const module = await moduleLoader.import(middlewarePath); const module = await moduleLoader.import(middlewarePath);
return module; return module;

View file

@ -8,7 +8,7 @@ describe('Adapter', () => {
it("should error if the adapter doesn't support edge middleware", async () => { it("should error if the adapter doesn't support edge middleware", async () => {
try { try {
fixture = await loadFixture({ fixture = await loadFixture({
root: './fixtures/middleware-dev/', root: './fixtures/middleware space/',
output: 'server', output: 'server',
build: { build: {
excludeMiddleware: true, excludeMiddleware: true,
@ -32,7 +32,7 @@ describe('Adapter', () => {
it("should error if the adapter doesn't support split build", async () => { it("should error if the adapter doesn't support split build", async () => {
try { try {
fixture = await loadFixture({ fixture = await loadFixture({
root: './fixtures/middleware-dev/', root: './fixtures/middleware space/',
output: 'server', output: 'server',
build: { build: {
split: true, split: true,

View file

@ -12,7 +12,7 @@ describe('Middleware in DEV mode', () => {
before(async () => { before(async () => {
fixture = await loadFixture({ fixture = await loadFixture({
root: './fixtures/middleware-dev/', root: './fixtures/middleware space/',
}); });
devServer = await fixture.startDevServer(); devServer = await fixture.startDevServer();
}); });
@ -116,7 +116,7 @@ describe('Middleware API in PROD mode, SSR', () => {
before(async () => { before(async () => {
fixture = await loadFixture({ fixture = await loadFixture({
root: './fixtures/middleware-dev/', root: './fixtures/middleware space/',
output: 'server', output: 'server',
adapter: testAdapter({}), adapter: testAdapter({}),
}); });
@ -223,7 +223,7 @@ describe('Middleware API in PROD mode, SSR', () => {
it('the integration should receive the path to the middleware', async () => { it('the integration should receive the path to the middleware', async () => {
fixture = await loadFixture({ fixture = await loadFixture({
root: './fixtures/middleware-dev/', root: './fixtures/middleware space/',
output: 'server', output: 'server',
build: { build: {
excludeMiddleware: true, excludeMiddleware: true,
@ -275,7 +275,7 @@ describe('Middleware, split middleware option', () => {
before(async () => { before(async () => {
fixture = await loadFixture({ fixture = await loadFixture({
root: './fixtures/middleware-dev/', root: './fixtures/middleware space/',
output: 'server', output: 'server',
build: { build: {
excludeMiddleware: true, excludeMiddleware: true,

View file

@ -2847,7 +2847,7 @@ importers:
specifier: workspace:* specifier: workspace:*
version: link:../../.. version: link:../../..
packages/astro/test/fixtures/middleware-dev: packages/astro/test/fixtures/middleware space:
dependencies: dependencies:
astro: astro:
specifier: workspace:* specifier: workspace:*