From 31f822e27da7abef84267dcd14a2f6c1e11d3790 Mon Sep 17 00:00:00 2001 From: wuls Date: Fri, 19 May 2023 16:35:51 +0800 Subject: [PATCH] sumbit test code --- packages/astro/src/core/preview/util.ts | 5 +---- packages/integrations/node/package.json | 1 + .../node/src}/get-network-address.ts | 0 packages/integrations/node/src/preview.ts | 7 ++++++- .../node/test/fixtures/url-protocol/package.json | 4 ++++ 5 files changed, 12 insertions(+), 5 deletions(-) rename packages/{astro/src/core/preview => integrations/node/src}/get-network-address.ts (100%) diff --git a/packages/astro/src/core/preview/util.ts b/packages/astro/src/core/preview/util.ts index 7a12417f3..d02e4c3c8 100644 --- a/packages/astro/src/core/preview/util.ts +++ b/packages/astro/src/core/preview/util.ts @@ -1,12 +1,10 @@ -import { getNetworkAddress } from './get-network-address.js' - export function getResolvedHostForHttpServer(host: string | boolean) { if (host === false) { // Use a secure default return 'localhost'; } else if (host === true) { // If passed --host in the CLI without arguments - return getNetworkAddress(); // undefined typically means 0.0.0.0 or :: (listen on all IPs) + return undefined; // undefined typically means 0.0.0.0 or :: (listen on all IPs) } else { return host; } @@ -19,4 +17,3 @@ export function stripBase(path: string, base: string): string { const baseWithSlash = base.endsWith('/') ? base : base + '/'; return path.replace(RegExp('^' + baseWithSlash), '/'); } - diff --git a/packages/integrations/node/package.json b/packages/integrations/node/package.json index 3306b2e57..d0c660a35 100644 --- a/packages/integrations/node/package.json +++ b/packages/integrations/node/package.json @@ -30,6 +30,7 @@ "build": "astro-scripts build \"src/**/*.ts\" && tsc", "build:ci": "astro-scripts build \"src/**/*.ts\"", "dev": "astro-scripts dev \"src/**/*.ts\"", + "t": "mocha --exit --timeout 20000 test/url-protocol.test.js", "test": "mocha --exit --timeout 20000 test/" }, "dependencies": { diff --git a/packages/astro/src/core/preview/get-network-address.ts b/packages/integrations/node/src/get-network-address.ts similarity index 100% rename from packages/astro/src/core/preview/get-network-address.ts rename to packages/integrations/node/src/get-network-address.ts diff --git a/packages/integrations/node/src/preview.ts b/packages/integrations/node/src/preview.ts index 92f9b86ba..7ef584c81 100644 --- a/packages/integrations/node/src/preview.ts +++ b/packages/integrations/node/src/preview.ts @@ -2,6 +2,7 @@ import type { CreatePreviewServer } from 'astro'; import type http from 'node:http'; import { fileURLToPath } from 'node:url'; import { createServer } from './http-server.js'; +import { getNetworkAddress } from './get-network-address.js' import type { createExports } from './server'; const preview: CreatePreviewServer = async function ({ @@ -58,6 +59,10 @@ const preview: CreatePreviewServer = async function ({ return pathname; } + if (!host){ + host = getNetworkAddress() + } + const server = createServer( { client, @@ -67,7 +72,7 @@ const preview: CreatePreviewServer = async function ({ }, handler ); - + // eslint-disable-next-line no-console console.log(`Preview server listening on http://${host}:${port}`); diff --git a/packages/integrations/node/test/fixtures/url-protocol/package.json b/packages/integrations/node/test/fixtures/url-protocol/package.json index 4b0775716..d894d0718 100644 --- a/packages/integrations/node/test/fixtures/url-protocol/package.json +++ b/packages/integrations/node/test/fixtures/url-protocol/package.json @@ -5,5 +5,9 @@ "dependencies": { "astro": "workspace:*", "@astrojs/node": "workspace:*" + }, + "scripts": { + "build": "astro build", + "preview": "astro preview" } }