mirror of
https://github.com/withastro/astro.git
synced 2025-01-27 22:19:04 -05:00
Merge branch 'main' into feat/phil-collins-closing-song
This commit is contained in:
commit
1e245eda40
41 changed files with 275 additions and 91 deletions
|
@ -1,5 +0,0 @@
|
|||
---
|
||||
"astro": patch
|
||||
---
|
||||
|
||||
Fixes a regression introduced in v4.4.5 where image optimization did not work in dev mode when a base was configured.
|
|
@ -1,5 +0,0 @@
|
|||
---
|
||||
"astro": patch
|
||||
---
|
||||
|
||||
Adds auto completion for `astro:` event names when adding or removing event listeners on `document`.
|
|
@ -11,6 +11,6 @@
|
|||
"astro": "astro"
|
||||
},
|
||||
"dependencies": {
|
||||
"astro": "^4.4.6"
|
||||
"astro": "^4.4.8"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,6 +14,6 @@
|
|||
"@astrojs/mdx": "^2.1.1",
|
||||
"@astrojs/rss": "^4.0.5",
|
||||
"@astrojs/sitemap": "^3.1.1",
|
||||
"astro": "^4.4.6"
|
||||
"astro": "^4.4.8"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
],
|
||||
"scripts": {},
|
||||
"devDependencies": {
|
||||
"astro": "^4.4.6"
|
||||
"astro": "^4.4.8"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"astro": "^4.0.0"
|
||||
|
|
|
@ -14,6 +14,6 @@
|
|||
"@astrojs/alpinejs": "^0.4.0",
|
||||
"@types/alpinejs": "^3.13.5",
|
||||
"alpinejs": "^3.13.3",
|
||||
"astro": "^4.4.6"
|
||||
"astro": "^4.4.8"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
"dependencies": {
|
||||
"@astrojs/lit": "^4.0.1",
|
||||
"@webcomponents/template-shadowroot": "^0.2.1",
|
||||
"astro": "^4.4.6",
|
||||
"astro": "^4.4.8",
|
||||
"lit": "^3.1.2"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
"@astrojs/solid-js": "^4.0.1",
|
||||
"@astrojs/svelte": "^5.2.0",
|
||||
"@astrojs/vue": "^4.0.8",
|
||||
"astro": "^4.4.6",
|
||||
"astro": "^4.4.8",
|
||||
"preact": "^10.19.2",
|
||||
"react": "^18.2.0",
|
||||
"react-dom": "^18.2.0",
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
"dependencies": {
|
||||
"@astrojs/preact": "^3.1.1",
|
||||
"@preact/signals": "^1.2.1",
|
||||
"astro": "^4.4.6",
|
||||
"astro": "^4.4.8",
|
||||
"preact": "^10.19.2"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
"@astrojs/react": "^3.0.10",
|
||||
"@types/react": "^18.2.37",
|
||||
"@types/react-dom": "^18.2.15",
|
||||
"astro": "^4.4.6",
|
||||
"astro": "^4.4.8",
|
||||
"react": "^18.2.0",
|
||||
"react-dom": "^18.2.0"
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
},
|
||||
"dependencies": {
|
||||
"@astrojs/solid-js": "^4.0.1",
|
||||
"astro": "^4.4.6",
|
||||
"astro": "^4.4.8",
|
||||
"solid-js": "^1.8.5"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
},
|
||||
"dependencies": {
|
||||
"@astrojs/svelte": "^5.2.0",
|
||||
"astro": "^4.4.6",
|
||||
"astro": "^4.4.8",
|
||||
"svelte": "^4.2.5"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
},
|
||||
"dependencies": {
|
||||
"@astrojs/vue": "^4.0.8",
|
||||
"astro": "^4.4.6",
|
||||
"astro": "^4.4.8",
|
||||
"vue": "^3.3.8"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
"astro": "astro"
|
||||
},
|
||||
"dependencies": {
|
||||
"@astrojs/node": "^8.2.1",
|
||||
"astro": "^4.4.6"
|
||||
"@astrojs/node": "^8.2.3",
|
||||
"astro": "^4.4.8"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
],
|
||||
"scripts": {},
|
||||
"devDependencies": {
|
||||
"astro": "^4.4.6"
|
||||
"astro": "^4.4.8"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"astro": "^4.0.0"
|
||||
|
|
|
@ -12,8 +12,8 @@
|
|||
"server": "node dist/server/entry.mjs"
|
||||
},
|
||||
"dependencies": {
|
||||
"@astrojs/node": "^8.2.1",
|
||||
"astro": "^4.4.6",
|
||||
"@astrojs/node": "^8.2.3",
|
||||
"astro": "^4.4.8",
|
||||
"html-minifier": "^4.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
|
|
@ -11,6 +11,6 @@
|
|||
"astro": "astro"
|
||||
},
|
||||
"dependencies": {
|
||||
"astro": "^4.4.6"
|
||||
"astro": "^4.4.8"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,6 +11,6 @@
|
|||
"astro": "astro"
|
||||
},
|
||||
"dependencies": {
|
||||
"astro": "^4.4.6"
|
||||
"astro": "^4.4.8"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,6 +11,6 @@
|
|||
"astro": "astro"
|
||||
},
|
||||
"dependencies": {
|
||||
"astro": "^4.4.6"
|
||||
"astro": "^4.4.8"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,9 +12,9 @@
|
|||
"server": "node dist/server/entry.mjs"
|
||||
},
|
||||
"dependencies": {
|
||||
"@astrojs/node": "^8.2.1",
|
||||
"@astrojs/node": "^8.2.3",
|
||||
"@astrojs/svelte": "^5.2.0",
|
||||
"astro": "^4.4.6",
|
||||
"astro": "^4.4.8",
|
||||
"svelte": "^4.2.5"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
"astro": "astro"
|
||||
},
|
||||
"dependencies": {
|
||||
"astro": "^4.4.6",
|
||||
"astro": "^4.4.8",
|
||||
"sass": "^1.69.5",
|
||||
"sharp": "^0.32.6"
|
||||
}
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
},
|
||||
"devDependencies": {
|
||||
"@astrojs/tailwind": "^5.1.0",
|
||||
"@astrojs/node": "^8.2.1",
|
||||
"astro": "^4.4.6"
|
||||
"@astrojs/node": "^8.2.3",
|
||||
"astro": "^4.4.8"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,6 +12,6 @@
|
|||
},
|
||||
"dependencies": {
|
||||
"@astrojs/markdoc": "^0.9.0",
|
||||
"astro": "^4.4.6"
|
||||
"astro": "^4.4.8"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
},
|
||||
"dependencies": {
|
||||
"@astrojs/markdown-remark": "^4.2.1",
|
||||
"astro": "^4.4.6",
|
||||
"astro": "^4.4.8",
|
||||
"hast-util-select": "^6.0.2",
|
||||
"rehype-autolink-headings": "^7.1.0",
|
||||
"rehype-slug": "^6.0.0",
|
||||
|
|
|
@ -11,6 +11,6 @@
|
|||
"astro": "astro"
|
||||
},
|
||||
"dependencies": {
|
||||
"astro": "^4.4.6"
|
||||
"astro": "^4.4.8"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
"dependencies": {
|
||||
"@astrojs/mdx": "^2.1.1",
|
||||
"@astrojs/preact": "^3.1.1",
|
||||
"astro": "^4.4.6",
|
||||
"astro": "^4.4.8",
|
||||
"preact": "^10.19.2"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
"dependencies": {
|
||||
"@astrojs/preact": "^3.1.1",
|
||||
"@nanostores/preact": "^0.5.0",
|
||||
"astro": "^4.4.6",
|
||||
"astro": "^4.4.8",
|
||||
"nanostores": "^0.9.5",
|
||||
"preact": "^10.19.2"
|
||||
}
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
"@astrojs/mdx": "^2.1.1",
|
||||
"@astrojs/tailwind": "^5.1.0",
|
||||
"@types/canvas-confetti": "^1.6.3",
|
||||
"astro": "^4.4.6",
|
||||
"astro": "^4.4.8",
|
||||
"autoprefixer": "^10.4.15",
|
||||
"canvas-confetti": "^1.9.1",
|
||||
"postcss": "^8.4.28",
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
"test": "vitest"
|
||||
},
|
||||
"dependencies": {
|
||||
"astro": "^4.4.6",
|
||||
"astro": "^4.4.8",
|
||||
"vitest": "^1.3.1"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,23 @@
|
|||
# astro
|
||||
|
||||
## 4.4.8
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- [#10275](https://github.com/withastro/astro/pull/10275) [`5e3e74b61daa2ba44c761c9ab5745818661a656e`](https://github.com/withastro/astro/commit/5e3e74b61daa2ba44c761c9ab5745818661a656e) Thanks [@Princesseuh](https://github.com/Princesseuh)! - Fixes dev toolbar warning about using the proper loading attributes on images using `data:` URIs
|
||||
|
||||
## 4.4.7
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- [#10274](https://github.com/withastro/astro/pull/10274) [`e556151603a2f0173059d0f98fdcbec0610b48ff`](https://github.com/withastro/astro/commit/e556151603a2f0173059d0f98fdcbec0610b48ff) Thanks [@lilnasy](https://github.com/lilnasy)! - Fixes a regression introduced in v4.4.5 where image optimization did not work in dev mode when a base was configured.
|
||||
|
||||
- [#10263](https://github.com/withastro/astro/pull/10263) [`9bdbed723e0aa4243d7d6ee64d1c1df3b75b9aeb`](https://github.com/withastro/astro/commit/9bdbed723e0aa4243d7d6ee64d1c1df3b75b9aeb) Thanks [@martrapp](https://github.com/martrapp)! - Adds auto completion for `astro:` event names when adding or removing event listeners on `document`.
|
||||
|
||||
- [#10284](https://github.com/withastro/astro/pull/10284) [`07f89429a1ef5173d3321e0b362a9dc71fc74fe5`](https://github.com/withastro/astro/commit/07f89429a1ef5173d3321e0b362a9dc71fc74fe5) Thanks [@Princesseuh](https://github.com/Princesseuh)! - Fixes an issue where in Node SSR, the image endpoint could be used maliciously to reveal unintended information about the underlying system.
|
||||
|
||||
Thanks to Google Security Team for reporting this issue.
|
||||
|
||||
## 4.4.6
|
||||
|
||||
### Patch Changes
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "astro",
|
||||
"version": "4.4.6",
|
||||
"version": "4.4.8",
|
||||
"description": "Astro is a modern site builder with web best practices, performance, and DX front-of-mind.",
|
||||
"type": "module",
|
||||
"author": "withastro",
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
import os from 'os';
|
||||
/* eslint-disable no-console */
|
||||
import os from 'node:os';
|
||||
import { isAbsolute } from 'node:path';
|
||||
import { fileURLToPath, pathToFileURL } from 'node:url';
|
||||
import { isRemotePath, removeQueryString } from '@astrojs/internal-helpers/path';
|
||||
import { readFile } from 'fs/promises';
|
||||
import mime from 'mime/lite.js';
|
||||
|
@ -7,23 +10,44 @@ import { getConfiguredImageService } from '../internal.js';
|
|||
import { etag } from '../utils/etag.js';
|
||||
import { isRemoteAllowed } from '../utils/remotePattern.js';
|
||||
// @ts-expect-error
|
||||
import { assetsDir, imageConfig } from 'astro:assets';
|
||||
import { assetsDir, imageConfig, outDir } from 'astro:assets';
|
||||
|
||||
function replaceFileSystemReferences(src: string) {
|
||||
return os.platform().includes('win32') ? src.replace(/^\/@fs\//, '') : src.replace(/^\/@fs/, '');
|
||||
}
|
||||
|
||||
async function loadLocalImage(src: string, url: URL) {
|
||||
const filePath = import.meta.env.DEV
|
||||
? removeQueryString(replaceFileSystemReferences(src))
|
||||
: new URL('.' + src, assetsDir);
|
||||
const assetsDirPath = fileURLToPath(assetsDir);
|
||||
|
||||
let fileUrl;
|
||||
if (import.meta.env.DEV) {
|
||||
fileUrl = pathToFileURL(removeQueryString(replaceFileSystemReferences(src)));
|
||||
} else {
|
||||
try {
|
||||
fileUrl = new URL('.' + src, outDir);
|
||||
const filePath = fileURLToPath(fileUrl);
|
||||
|
||||
if (!isAbsolute(filePath) || !filePath.startsWith(assetsDirPath)) {
|
||||
return undefined;
|
||||
}
|
||||
} catch (err: unknown) {
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
let buffer: Buffer | undefined = undefined;
|
||||
|
||||
try {
|
||||
buffer = await readFile(filePath);
|
||||
buffer = await readFile(fileUrl);
|
||||
} catch (e) {
|
||||
const sourceUrl = new URL(src, url.origin);
|
||||
buffer = await loadRemoteImage(sourceUrl);
|
||||
// Fallback to try to load the file using `fetch`
|
||||
try {
|
||||
const sourceUrl = new URL(src, url.origin);
|
||||
buffer = await loadRemoteImage(sourceUrl);
|
||||
} catch (err: unknown) {
|
||||
console.error('Could not process image request:', err);
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
return buffer;
|
||||
|
@ -58,7 +82,11 @@ export const GET: APIRoute = async ({ request }) => {
|
|||
const transform = await imageService.parseURL(url, imageConfig);
|
||||
|
||||
if (!transform?.src) {
|
||||
throw new Error('Incorrect transform returned by `parseURL`');
|
||||
const err = new Error(
|
||||
'Incorrect transform returned by `parseURL`. Expected a transform with a `src` property.'
|
||||
);
|
||||
console.error('Could not parse image transform from URL:', err);
|
||||
return new Response('Internal Server Error', { status: 500 });
|
||||
}
|
||||
|
||||
let inputBuffer: Buffer | undefined = undefined;
|
||||
|
@ -74,7 +102,7 @@ export const GET: APIRoute = async ({ request }) => {
|
|||
}
|
||||
|
||||
if (!inputBuffer) {
|
||||
return new Response('Not Found', { status: 404 });
|
||||
return new Response('Internal Server Error', { status: 500 });
|
||||
}
|
||||
|
||||
const { data, format } = await imageService.transform(inputBuffer, transform, imageConfig);
|
||||
|
@ -89,8 +117,12 @@ export const GET: APIRoute = async ({ request }) => {
|
|||
},
|
||||
});
|
||||
} catch (err: unknown) {
|
||||
// eslint-disable-next-line no-console
|
||||
console.error('Could not process image request:', err);
|
||||
return new Response(`Server Error: ${err}`, { status: 500 });
|
||||
return new Response(
|
||||
import.meta.env.DEV ? `Could not process image request: ${err}` : `Internal Server Error`,
|
||||
{
|
||||
status: 500,
|
||||
}
|
||||
);
|
||||
}
|
||||
};
|
||||
|
|
|
@ -66,13 +66,14 @@ export default function assets({
|
|||
export { default as Picture } from "astro/components/Picture.astro";
|
||||
|
||||
export const imageConfig = ${JSON.stringify(settings.config.image)};
|
||||
export const assetsDir = new URL(${JSON.stringify(
|
||||
export const outDir = new URL(${JSON.stringify(
|
||||
new URL(
|
||||
isServerLikeOutput(settings.config)
|
||||
? settings.config.build.client
|
||||
: settings.config.outDir
|
||||
)
|
||||
)});
|
||||
export const assetsDir = new URL(${JSON.stringify(settings.config.build.assets)}, outDir);
|
||||
export const getImage = async (options) => await getImageInternal(options, imageConfig);
|
||||
`;
|
||||
}
|
||||
|
|
|
@ -38,6 +38,9 @@ export const perf: AuditRuleWithSelector[] = [
|
|||
// Ignore elements that are above the fold, they should be loaded eagerly
|
||||
if (htmlElement.offsetTop < window.innerHeight) return false;
|
||||
|
||||
// Ignore elements using `data:` URI, the `loading` attribute doesn't do anything for these
|
||||
if (htmlElement.src.startsWith('data:')) return false;
|
||||
|
||||
return true;
|
||||
},
|
||||
},
|
||||
|
@ -53,6 +56,9 @@ export const perf: AuditRuleWithSelector[] = [
|
|||
// Ignore elements that are below the fold, they should be loaded lazily
|
||||
if (htmlElement.offsetTop > window.innerHeight) return false;
|
||||
|
||||
// Ignore elements using `data:` URI, the `loading` attribute doesn't do anything for these
|
||||
if (htmlElement.src.startsWith('data:')) return false;
|
||||
|
||||
return true;
|
||||
},
|
||||
},
|
||||
|
|
|
@ -1103,6 +1103,96 @@ describe('astro:image', () => {
|
|||
assert.equal(response.status, 200);
|
||||
});
|
||||
|
||||
it('endpoint handle malformed requests', async () => {
|
||||
const badPaths = [
|
||||
'../../../../../../../../../../../../etc/hosts%00',
|
||||
'../../../../../../../../../../../../etc/hosts',
|
||||
'../../boot.ini',
|
||||
'/../../../../../../../../%2A',
|
||||
'../../../../../../../../../../../../etc/passwd%00',
|
||||
'../../../../../../../../../../../../etc/passwd',
|
||||
'../../../../../../../../../../../../etc/shadow%00',
|
||||
'../../../../../../../../../../../../etc/shadow',
|
||||
'/../../../../../../../../../../etc/passwd^^',
|
||||
'/../../../../../../../../../../etc/shadow^^',
|
||||
'/../../../../../../../../../../etc/passwd',
|
||||
'/../../../../../../../../../../etc/shadow',
|
||||
'/./././././././././././etc/passwd',
|
||||
'/./././././././././././etc/shadow',
|
||||
'....................etcpasswd',
|
||||
'....................etcshadow',
|
||||
'....................etcpasswd',
|
||||
'....................etcshadow',
|
||||
'/..../..../..../..../..../..../etc/passwd',
|
||||
'/..../..../..../..../..../..../etc/shadow',
|
||||
'.\\./.\\./.\\./.\\./.\\./.\\./etc/passwd',
|
||||
'.\\./.\\./.\\./.\\./.\\./.\\./etc/shadow',
|
||||
'....................etcpasswd%00',
|
||||
'....................etcshadow%00',
|
||||
'....................etcpasswd%00',
|
||||
'....................etcshadow%00',
|
||||
'%0a/bin/cat%20/etc/passwd',
|
||||
'%0a/bin/cat%20/etc/shadow',
|
||||
'%00/etc/passwd%00',
|
||||
'%00/etc/shadow%00',
|
||||
'%00../../../../../../etc/passwd',
|
||||
'%00../../../../../../etc/shadow',
|
||||
'/../../../../../../../../../../../etc/passwd%00.jpg',
|
||||
'/../../../../../../../../../../../etc/passwd%00.html',
|
||||
'/..%c0%af../..%c0%af../..%c0%af../..%c0%af../..%c0%af../..%c0%af../etc/passwd',
|
||||
'/..%c0%af../..%c0%af../..%c0%af../..%c0%af../..%c0%af../..%c0%af../etc/shadow',
|
||||
'/%2e%2e/%2e%2e/%2e%2e/%2e%2e/%2e%2e/%2e%2e/%2e%2e/%2e%2e/%2e%2e/%2e%2e/etc/passwd,',
|
||||
'/%2e%2e/%2e%2e/%2e%2e/%2e%2e/%2e%2e/%2e%2e/%2e%2e/%2e%2e/%2e%2e/%2e%2e/etc/shadow,',
|
||||
'%25%5c..%25%5c..%25%5c..%25%5c..%25%5c..%25%5c..%25%5c..%25%5c..%25%5c..%25%5c..%,25%5c..%25%5c..%25%5c..%25%5c..%00',
|
||||
'/%25%5c..%25%5c..%25%5c..%25%5c..%25%5c..%25%5c..%25%5c..%25%5c..%25%5c..%25%5c..,%25%5c..%25%5c..%25%5c..%25%5c..%00',
|
||||
'%25%5c..%25%5c..%25%5c..%25%5c..%25%5c..%25%5c..%25%5c..%25%5c..%25%5c..%25%5c..%,25%5c..%25%5c..% 25%5c..%25%5c..%00',
|
||||
'%25%5c..%25%5c..%25%5c..%25%5c..%25%5c..%25%5c..%25%5c..%25%5c..%25%5c..%25%5c..%,25%5c..%25%5c..% 25%5c..%25%5c..%255cboot.ini',
|
||||
'/%25%5c..%25%5c..%25%5c..%25%5c..%25%5c..%25%5c..%25%5c..%25%5c..%25%5c..%25%5c..,%25%5c..%25%5c..%25%5c..%25%5c..winnt/desktop.ini',
|
||||
'\\'/bin/cat%20/etc/passwd\\'',
|
||||
'\\'/bin/cat%20/etc/shadow\\'',
|
||||
'../../../../../../../../conf/server.xml',
|
||||
'/../../../../../../../../bin/id|',
|
||||
'C:/inetpub/wwwroot/global.asa',
|
||||
'C:inetpubwwwrootglobal.asa',
|
||||
'C:/boot.ini',
|
||||
'C:\boot.ini',
|
||||
'../../../../../../../../../../../../localstart.asp%00',
|
||||
'../../../../../../../../../../../../localstart.asp',
|
||||
'../../../../../../../../../../../../boot.ini%00',
|
||||
'../../../../../../../../../../../../boot.ini',
|
||||
'/./././././././././././boot.ini',
|
||||
'/../../../../../../../../../../../boot.ini%00',
|
||||
'/../../../../../../../../../../../boot.ini',
|
||||
'/..../..../..../..../..../..../boot.ini',
|
||||
'/.\\./.\\./.\\./.\\./.\\./.\\./boot.ini',
|
||||
'....................\boot.ini',
|
||||
'....................\boot.ini%00',
|
||||
'....................\boot.ini',
|
||||
'/../../../../../../../../../../../boot.ini%00.html',
|
||||
'/../../../../../../../../../../../boot.ini%00.jpg',
|
||||
'/.../.../.../.../.../ ',
|
||||
'..%c0%af../..%c0%af../..%c0%af../..%c0%af../..%c0%af../..%c0%af../boot.ini',
|
||||
'/%2e%2e/%2e%2e/%2e%2e/%2e%2e/%2e%2e/%2e%2e/%2e%2e/%2e%2e/%2e%2e/%2e%2e/boot.ini',
|
||||
'../prerender/index.html',
|
||||
];
|
||||
|
||||
const app = await fixture.loadTestAdapterApp();
|
||||
|
||||
for (const path of badPaths) {
|
||||
let request = new Request('http://example.com/_image?href=' + path);
|
||||
let response = await app.render(request);
|
||||
const body = await response.text();
|
||||
|
||||
assert.equal(response.status, 500);
|
||||
assert.equal(body.includes('Internal Server Error'), true);
|
||||
}
|
||||
|
||||
// Server should still be running
|
||||
let request = new Request('http://example.com/');
|
||||
let response = await app.render(request);
|
||||
assert.equal(response.status, 200);
|
||||
});
|
||||
|
||||
it('prerendered routes images are built', async () => {
|
||||
const html = await fixture.readFile('/client/prerender/index.html');
|
||||
const $ = cheerio.load(html);
|
||||
|
|
|
@ -1,5 +1,17 @@
|
|||
# @astrojs/node
|
||||
|
||||
## 8.2.3
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- [#10285](https://github.com/withastro/astro/pull/10285) [`d5277df5a4d1e9a8a7b6c8d7b87912e13a163f7f`](https://github.com/withastro/astro/commit/d5277df5a4d1e9a8a7b6c8d7b87912e13a163f7f) Thanks [@Princesseuh](https://github.com/Princesseuh)! - Fixes an issue where malformed requests could cause the server to error in certain cases.
|
||||
|
||||
## 8.2.2
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- [#10282](https://github.com/withastro/astro/pull/10282) [`b47dcaa25968ec85ba96fce23381c94a94e389f6`](https://github.com/withastro/astro/commit/b47dcaa25968ec85ba96fce23381c94a94e389f6) Thanks [@SatanshuMishra](https://github.com/SatanshuMishra)! - Fixes the `server.host` option to properly listen on all network interfaces when set to `true`
|
||||
|
||||
## 8.2.1
|
||||
|
||||
### Patch Changes
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"name": "@astrojs/node",
|
||||
"description": "Deploy your site to a Node.js server",
|
||||
"version": "8.2.1",
|
||||
"version": "8.2.3",
|
||||
"type": "module",
|
||||
"types": "./dist/index.d.ts",
|
||||
"author": "withastro",
|
||||
|
|
|
@ -8,7 +8,15 @@ import type { RequestHandler } from './types.js';
|
|||
*/
|
||||
export function createAppHandler(app: NodeApp): RequestHandler {
|
||||
return async (req, res, next, locals) => {
|
||||
const request = NodeApp.createRequest(req);
|
||||
let request;
|
||||
try {
|
||||
request = NodeApp.createRequest(req);
|
||||
} catch (err) {
|
||||
res.statusCode = 500;
|
||||
res.end('Internal Server Error');
|
||||
return;
|
||||
}
|
||||
|
||||
const routeData = app.match(request);
|
||||
if (routeData) {
|
||||
const response = await app.render(request, {
|
||||
|
|
|
@ -9,11 +9,17 @@ import { createAppHandler } from './serve-app.js';
|
|||
import { createStaticHandler } from './serve-static.js';
|
||||
import type { Options } from './types.js';
|
||||
|
||||
// Used to get Host Value at Runtime
|
||||
export const hostOptions = (host: Options['host']): string => {
|
||||
if (typeof host === 'boolean') {
|
||||
return host ? '0.0.0.0' : 'localhost';
|
||||
}
|
||||
return host;
|
||||
};
|
||||
|
||||
export default function standalone(app: NodeApp, options: Options) {
|
||||
const port = process.env.PORT ? Number(process.env.PORT) : options.port ?? 8080;
|
||||
// Allow to provide host value at runtime
|
||||
const hostOptions = typeof options.host === 'boolean' ? 'localhost' : options.host;
|
||||
const host = process.env.HOST ?? hostOptions;
|
||||
const host = process.env.HOST ?? hostOptions(options.host);
|
||||
const handler = createStandaloneHandler(app, options);
|
||||
const server = createServer(handler, host, port);
|
||||
server.server.listen(port, host);
|
||||
|
|
21
packages/integrations/node/test/server-host.test.js
Normal file
21
packages/integrations/node/test/server-host.test.js
Normal file
|
@ -0,0 +1,21 @@
|
|||
import * as assert from 'node:assert/strict';
|
||||
import { describe, it } from 'node:test';
|
||||
import { hostOptions } from '../dist/standalone.js';
|
||||
|
||||
describe('host', () => {
|
||||
it('returns "0.0.0.0" when host is true', () => {
|
||||
const options = { host: true };
|
||||
assert.equal(hostOptions(options.host), '0.0.0.0');
|
||||
});
|
||||
|
||||
it('returns "localhost" when host is false', () => {
|
||||
const options = { host: false };
|
||||
assert.equal(hostOptions(options.host), 'localhost');
|
||||
});
|
||||
|
||||
it('returns the value of host when host is a string', () => {
|
||||
const host = '1.1.1.1';
|
||||
const options = { host };
|
||||
assert.equal(hostOptions(options.host), host);
|
||||
});
|
||||
});
|
62
pnpm-lock.yaml
generated
62
pnpm-lock.yaml
generated
|
@ -134,7 +134,7 @@ importers:
|
|||
examples/basics:
|
||||
dependencies:
|
||||
astro:
|
||||
specifier: ^4.4.6
|
||||
specifier: ^4.4.8
|
||||
version: link:../../packages/astro
|
||||
|
||||
examples/blog:
|
||||
|
@ -149,13 +149,13 @@ importers:
|
|||
specifier: ^3.1.1
|
||||
version: link:../../packages/integrations/sitemap
|
||||
astro:
|
||||
specifier: ^4.4.6
|
||||
specifier: ^4.4.8
|
||||
version: link:../../packages/astro
|
||||
|
||||
examples/component:
|
||||
devDependencies:
|
||||
astro:
|
||||
specifier: ^4.4.6
|
||||
specifier: ^4.4.8
|
||||
version: link:../../packages/astro
|
||||
|
||||
examples/framework-alpine:
|
||||
|
@ -170,7 +170,7 @@ importers:
|
|||
specifier: ^3.13.3
|
||||
version: 3.13.3
|
||||
astro:
|
||||
specifier: ^4.4.6
|
||||
specifier: ^4.4.8
|
||||
version: link:../../packages/astro
|
||||
|
||||
examples/framework-lit:
|
||||
|
@ -182,7 +182,7 @@ importers:
|
|||
specifier: ^0.2.1
|
||||
version: 0.2.1
|
||||
astro:
|
||||
specifier: ^4.4.6
|
||||
specifier: ^4.4.8
|
||||
version: link:../../packages/astro
|
||||
lit:
|
||||
specifier: ^3.1.2
|
||||
|
@ -206,7 +206,7 @@ importers:
|
|||
specifier: ^4.0.8
|
||||
version: link:../../packages/integrations/vue
|
||||
astro:
|
||||
specifier: ^4.4.6
|
||||
specifier: ^4.4.8
|
||||
version: link:../../packages/astro
|
||||
preact:
|
||||
specifier: ^10.19.2
|
||||
|
@ -236,7 +236,7 @@ importers:
|
|||
specifier: ^1.2.1
|
||||
version: 1.2.1(preact@10.19.3)
|
||||
astro:
|
||||
specifier: ^4.4.6
|
||||
specifier: ^4.4.8
|
||||
version: link:../../packages/astro
|
||||
preact:
|
||||
specifier: ^10.19.2
|
||||
|
@ -254,7 +254,7 @@ importers:
|
|||
specifier: ^18.2.15
|
||||
version: 18.2.18
|
||||
astro:
|
||||
specifier: ^4.4.6
|
||||
specifier: ^4.4.8
|
||||
version: link:../../packages/astro
|
||||
react:
|
||||
specifier: ^18.2.0
|
||||
|
@ -269,7 +269,7 @@ importers:
|
|||
specifier: ^4.0.1
|
||||
version: link:../../packages/integrations/solid
|
||||
astro:
|
||||
specifier: ^4.4.6
|
||||
specifier: ^4.4.8
|
||||
version: link:../../packages/astro
|
||||
solid-js:
|
||||
specifier: ^1.8.5
|
||||
|
@ -281,7 +281,7 @@ importers:
|
|||
specifier: ^5.2.0
|
||||
version: link:../../packages/integrations/svelte
|
||||
astro:
|
||||
specifier: ^4.4.6
|
||||
specifier: ^4.4.8
|
||||
version: link:../../packages/astro
|
||||
svelte:
|
||||
specifier: ^4.2.5
|
||||
|
@ -293,7 +293,7 @@ importers:
|
|||
specifier: ^4.0.8
|
||||
version: link:../../packages/integrations/vue
|
||||
astro:
|
||||
specifier: ^4.4.6
|
||||
specifier: ^4.4.8
|
||||
version: link:../../packages/astro
|
||||
vue:
|
||||
specifier: ^3.3.8
|
||||
|
@ -302,25 +302,25 @@ importers:
|
|||
examples/hackernews:
|
||||
dependencies:
|
||||
'@astrojs/node':
|
||||
specifier: ^8.2.1
|
||||
specifier: ^8.2.3
|
||||
version: link:../../packages/integrations/node
|
||||
astro:
|
||||
specifier: ^4.4.6
|
||||
specifier: ^4.4.8
|
||||
version: link:../../packages/astro
|
||||
|
||||
examples/integration:
|
||||
devDependencies:
|
||||
astro:
|
||||
specifier: ^4.4.6
|
||||
specifier: ^4.4.8
|
||||
version: link:../../packages/astro
|
||||
|
||||
examples/middleware:
|
||||
dependencies:
|
||||
'@astrojs/node':
|
||||
specifier: ^8.2.1
|
||||
specifier: ^8.2.3
|
||||
version: link:../../packages/integrations/node
|
||||
astro:
|
||||
specifier: ^4.4.6
|
||||
specifier: ^4.4.8
|
||||
version: link:../../packages/astro
|
||||
html-minifier:
|
||||
specifier: ^4.0.0
|
||||
|
@ -333,31 +333,31 @@ importers:
|
|||
examples/minimal:
|
||||
dependencies:
|
||||
astro:
|
||||
specifier: ^4.4.6
|
||||
specifier: ^4.4.8
|
||||
version: link:../../packages/astro
|
||||
|
||||
examples/non-html-pages:
|
||||
dependencies:
|
||||
astro:
|
||||
specifier: ^4.4.6
|
||||
specifier: ^4.4.8
|
||||
version: link:../../packages/astro
|
||||
|
||||
examples/portfolio:
|
||||
dependencies:
|
||||
astro:
|
||||
specifier: ^4.4.6
|
||||
specifier: ^4.4.8
|
||||
version: link:../../packages/astro
|
||||
|
||||
examples/ssr:
|
||||
dependencies:
|
||||
'@astrojs/node':
|
||||
specifier: ^8.2.1
|
||||
specifier: ^8.2.3
|
||||
version: link:../../packages/integrations/node
|
||||
'@astrojs/svelte':
|
||||
specifier: ^5.2.0
|
||||
version: link:../../packages/integrations/svelte
|
||||
astro:
|
||||
specifier: ^4.4.6
|
||||
specifier: ^4.4.8
|
||||
version: link:../../packages/astro
|
||||
svelte:
|
||||
specifier: ^4.2.5
|
||||
|
@ -366,7 +366,7 @@ importers:
|
|||
examples/starlog:
|
||||
dependencies:
|
||||
astro:
|
||||
specifier: ^4.4.6
|
||||
specifier: ^4.4.8
|
||||
version: link:../../packages/astro
|
||||
sass:
|
||||
specifier: ^1.69.5
|
||||
|
@ -378,13 +378,13 @@ importers:
|
|||
examples/view-transitions:
|
||||
devDependencies:
|
||||
'@astrojs/node':
|
||||
specifier: ^8.2.1
|
||||
specifier: ^8.2.3
|
||||
version: link:../../packages/integrations/node
|
||||
'@astrojs/tailwind':
|
||||
specifier: ^5.1.0
|
||||
version: link:../../packages/integrations/tailwind
|
||||
astro:
|
||||
specifier: ^4.4.6
|
||||
specifier: ^4.4.8
|
||||
version: link:../../packages/astro
|
||||
|
||||
examples/with-markdoc:
|
||||
|
@ -393,7 +393,7 @@ importers:
|
|||
specifier: ^0.9.0
|
||||
version: link:../../packages/integrations/markdoc
|
||||
astro:
|
||||
specifier: ^4.4.6
|
||||
specifier: ^4.4.8
|
||||
version: link:../../packages/astro
|
||||
|
||||
examples/with-markdown-plugins:
|
||||
|
@ -402,7 +402,7 @@ importers:
|
|||
specifier: ^4.2.1
|
||||
version: link:../../packages/markdown/remark
|
||||
astro:
|
||||
specifier: ^4.4.6
|
||||
specifier: ^4.4.8
|
||||
version: link:../../packages/astro
|
||||
hast-util-select:
|
||||
specifier: ^6.0.2
|
||||
|
@ -423,7 +423,7 @@ importers:
|
|||
examples/with-markdown-shiki:
|
||||
dependencies:
|
||||
astro:
|
||||
specifier: ^4.4.6
|
||||
specifier: ^4.4.8
|
||||
version: link:../../packages/astro
|
||||
|
||||
examples/with-mdx:
|
||||
|
@ -435,7 +435,7 @@ importers:
|
|||
specifier: ^3.1.1
|
||||
version: link:../../packages/integrations/preact
|
||||
astro:
|
||||
specifier: ^4.4.6
|
||||
specifier: ^4.4.8
|
||||
version: link:../../packages/astro
|
||||
preact:
|
||||
specifier: ^10.19.2
|
||||
|
@ -450,7 +450,7 @@ importers:
|
|||
specifier: ^0.5.0
|
||||
version: 0.5.0(nanostores@0.9.5)(preact@10.19.3)
|
||||
astro:
|
||||
specifier: ^4.4.6
|
||||
specifier: ^4.4.8
|
||||
version: link:../../packages/astro
|
||||
nanostores:
|
||||
specifier: ^0.9.5
|
||||
|
@ -471,7 +471,7 @@ importers:
|
|||
specifier: ^1.6.3
|
||||
version: 1.6.4
|
||||
astro:
|
||||
specifier: ^4.4.6
|
||||
specifier: ^4.4.8
|
||||
version: link:../../packages/astro
|
||||
autoprefixer:
|
||||
specifier: ^10.4.15
|
||||
|
@ -489,7 +489,7 @@ importers:
|
|||
examples/with-vitest:
|
||||
dependencies:
|
||||
astro:
|
||||
specifier: ^4.4.6
|
||||
specifier: ^4.4.8
|
||||
version: link:../../packages/astro
|
||||
vitest:
|
||||
specifier: ^1.3.1
|
||||
|
|
Loading…
Add table
Reference in a new issue