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) {
if (id === MIDDLEWARE_MODULE_ID) {
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) {
resolvedMiddlewareId = middlewareId.id;

View file

@ -12,7 +12,7 @@ export async function loadMiddleware(
srcDir: AstroSettings['config']['srcDir']
) {
// 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 {
const module = await moduleLoader.import(middlewarePath);
return module;

View file

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

View file

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

View file

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