-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(middleware): do not import user middleware if not preset (#9057)
- Loading branch information
Showing
13 changed files
with
123 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'astro': patch | ||
--- | ||
|
||
Correctly infer the presence of an user middleware |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 4 additions & 4 deletions
8
packages/astro/test/fixtures/middleware space/integration-middleware-post.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 4 additions & 4 deletions
8
packages/astro/test/fixtures/middleware space/integration-middleware-pre.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
packages/astro/test/fixtures/middleware-no-user-middleware/astro.config.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import {defineConfig} from "astro/config"; | ||
import {fileURLToPath} from "node:url"; | ||
|
||
export default defineConfig({ | ||
integrations: [ | ||
{ | ||
name: 'my-middleware', | ||
hooks: { | ||
'astro:config:setup':({ addMiddleware }) => { | ||
addMiddleware({ | ||
entrypoint: fileURLToPath(new URL('./integration-middleware-pre.js', import.meta.url)), | ||
order: 'pre' | ||
}); | ||
|
||
addMiddleware({ | ||
entrypoint: fileURLToPath(new URL('./integration-middleware-post.js', import.meta.url)), | ||
order: 'post' | ||
}); | ||
} | ||
} | ||
} | ||
] | ||
}); |
13 changes: 13 additions & 0 deletions
13
packages/astro/test/fixtures/middleware-no-user-middleware/integration-middleware-post.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { defineMiddleware } from 'astro:middleware'; | ||
|
||
export const onRequest = defineMiddleware((context, next) => { | ||
if (context.url.pathname === '/post') { | ||
return new Response(JSON.stringify({ post: 'works' }), { | ||
headers: { | ||
'content-type': 'application/json', | ||
}, | ||
}); | ||
} | ||
|
||
return next(); | ||
}); |
13 changes: 13 additions & 0 deletions
13
packages/astro/test/fixtures/middleware-no-user-middleware/integration-middleware-pre.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { defineMiddleware } from 'astro:middleware'; | ||
|
||
export const onRequest = defineMiddleware((context, next) => { | ||
if (context.url.pathname === '/pre') { | ||
return new Response(JSON.stringify({ pre: 'works' }), { | ||
headers: { | ||
'content-type': 'application/json', | ||
}, | ||
}); | ||
} | ||
|
||
return next(); | ||
}); |
8 changes: 8 additions & 0 deletions
8
packages/astro/test/fixtures/middleware-no-user-middleware/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"name": "@test/middleware-no-user-middlewaqre", | ||
"version": "0.0.0", | ||
"private": true, | ||
"dependencies": { | ||
"astro": "workspace:*" | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
packages/astro/test/fixtures/middleware-no-user-middleware/src/pages/index.astro
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
--- | ||
const data = Astro.locals; | ||
--- | ||
|
||
<html> | ||
<head> | ||
<title>Testing</title> | ||
</head> | ||
<body> | ||
|
||
<span>Index</span> | ||
<p>{data?.name}</p> | ||
</body> | ||
</html> |
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.