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: astro:env secret in middleware #12326

Draft
wants to merge 25 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
6b92e0b
fix: astro:env secret in middleware
florian-lefebvre Oct 28, 2024
9c03972
fix: do not emit file
florian-lefebvre Oct 28, 2024
5ea167e
Update packages/astro/src/core/build/plugins/plugin-ssr.ts
florian-lefebvre Oct 28, 2024
cc891cc
Discard changes to packages/astro/test/env-secret.test.js
florian-lefebvre Oct 28, 2024
08d3706
Discard changes to packages/astro/src/core/middleware/vite-plugin.ts
florian-lefebvre Oct 28, 2024
d1311e6
feat: import internal middleware directly
florian-lefebvre Oct 29, 2024
11770f9
directly import internal middleware
florian-lefebvre Oct 29, 2024
bd35b98
feat: refine check
florian-lefebvre Oct 29, 2024
d96d2aa
feat: simplify
florian-lefebvre Oct 31, 2024
f329071
Merge branch 'main' into fix/env-secret-middleware
florian-lefebvre Oct 31, 2024
f29ee41
fix: test
florian-lefebvre Oct 31, 2024
7f49c96
chore: changeset
florian-lefebvre Oct 31, 2024
89d3908
feat: update middleware check
florian-lefebvre Oct 31, 2024
931781b
feat: improve test
florian-lefebvre Oct 31, 2024
cd8f6ee
chore: add failing test for static pages
ematipico Nov 4, 2024
36f3433
Update pipeline.ts
florian-lefebvre Nov 5, 2024
b675665
fix: test
florian-lefebvre Nov 5, 2024
5a82302
feat: improve test adapter
florian-lefebvre Nov 5, 2024
9b52c61
Merge branch 'main' into fix/env-secret-middleware
florian-lefebvre Nov 5, 2024
46de5f7
feat: add back code
florian-lefebvre Nov 5, 2024
27e83fe
fix: test
florian-lefebvre Nov 5, 2024
c17d691
Discard changes to packages/astro/src/core/build/plugins/plugin-pages.ts
florian-lefebvre Nov 18, 2024
6bb6f1f
Update vite-plugin.ts
florian-lefebvre Nov 18, 2024
d984213
Update runtime.ts
florian-lefebvre Nov 18, 2024
9eca2cb
Merge branch 'main' into fix/env-secret-middleware
florian-lefebvre Nov 18, 2024
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
1 change: 0 additions & 1 deletion packages/astro/src/core/build/plugins/plugin-ssr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,6 @@ function generateSSRCode(settings: AstroSettings, adapter: AstroAdapter, middlew
`import { renderers } from '${RENDERERS_MODULE_ID}';`,
`import * as serverEntrypointModule from '${ADAPTER_VIRTUAL_MODULE_ID}';`,
`import { manifest as defaultManifest } from '${SSR_MANIFEST_VIRTUAL_MODULE_ID}';`,
edgeMiddleware ? `` : `import { onRequest as middleware } from '${middlewareId}';`,
florian-lefebvre marked this conversation as resolved.
Show resolved Hide resolved
settings.config.experimental.serverIslands
? `import { serverIslandMap } from '${VIRTUAL_ISLAND_MAP_ID}';`
: '',
Expand Down
9 changes: 0 additions & 9 deletions packages/astro/src/core/middleware/vite-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
const NOOP_MIDDLEWARE = '\0noop-middleware';

export function vitePluginMiddleware({ settings }: { settings: AstroSettings }): VitePlugin {
let isCommandBuild = false;

Check notice on line 16 in packages/astro/src/core/middleware/vite-plugin.ts

View workflow job for this annotation

GitHub Actions / Lint

lint/correctness/noUnusedVariables

This variable is unused.
let resolvedMiddlewareId: string | undefined = undefined;
const hasIntegrationMiddleware =
settings.middlewares.pre.length > 0 || settings.middlewares.post.length > 0;
Expand Down Expand Up @@ -54,15 +54,6 @@
if (!userMiddlewareIsPresent && settings.config.i18n?.routing === 'manual') {
throw new AstroError(MissingMiddlewareForInternationalization);
}
// In the build, tell Vite to emit this file
if (isCommandBuild) {
this.emitFile({
type: 'chunk',
florian-lefebvre marked this conversation as resolved.
Show resolved Hide resolved
preserveSignature: 'strict',
fileName: 'middleware.mjs',
id,
});
}

const preMiddleware = createMiddlewareImports(settings.middlewares.pre, 'pre');
const postMiddleware = createMiddlewareImports(settings.middlewares.post, 'post');
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { defineMiddleware } from 'astro/middleware';
import { KNOWN_SECRET } from 'astro:env/server';

export const onRequest = defineMiddleware(async (ctx, next) => {
console.log({ KNOWN_SECRET });
return await next();
});
Loading