Skip to content

Commit

Permalink
fix(middleware): undo config's path to URL encoding (#8614)
Browse files Browse the repository at this point in the history
* fix(middleware): undo config's path to URL encoding

* add changeset

* middleware-dev => "middleware space"
  • Loading branch information
lilnasy authored Sep 21, 2023
1 parent b4034aa commit 4398e92
Show file tree
Hide file tree
Showing 20 changed files with 14 additions and 9 deletions.
5 changes: 5 additions & 0 deletions .changeset/tidy-kiwis-lick.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'astro': patch
---

Fixed an issue where spaces and unicode characters in project path prevented middleware from running.
2 changes: 1 addition & 1 deletion packages/astro/src/core/build/plugins/plugin-middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/src/core/middleware/loadMiddleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions packages/astro/test/featuresSupport.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down
8 changes: 4 additions & 4 deletions packages/astro/test/middleware.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
Expand Down Expand Up @@ -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({}),
});
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 4398e92

Please sign in to comment.