sumbit test code

This commit is contained in:
wuls 2023-05-19 16:35:51 +08:00 committed by Nate Moore
parent bb0b0169c7
commit 31f822e27d
5 changed files with 12 additions and 5 deletions

View file

@ -1,12 +1,10 @@
import { getNetworkAddress } from './get-network-address.js'
export function getResolvedHostForHttpServer(host: string | boolean) { export function getResolvedHostForHttpServer(host: string | boolean) {
if (host === false) { if (host === false) {
// Use a secure default // Use a secure default
return 'localhost'; return 'localhost';
} else if (host === true) { } else if (host === true) {
// If passed --host in the CLI without arguments // 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 { } else {
return host; return host;
} }
@ -19,4 +17,3 @@ export function stripBase(path: string, base: string): string {
const baseWithSlash = base.endsWith('/') ? base : base + '/'; const baseWithSlash = base.endsWith('/') ? base : base + '/';
return path.replace(RegExp('^' + baseWithSlash), '/'); return path.replace(RegExp('^' + baseWithSlash), '/');
} }

View file

@ -30,6 +30,7 @@
"build": "astro-scripts build \"src/**/*.ts\" && tsc", "build": "astro-scripts build \"src/**/*.ts\" && tsc",
"build:ci": "astro-scripts build \"src/**/*.ts\"", "build:ci": "astro-scripts build \"src/**/*.ts\"",
"dev": "astro-scripts dev \"src/**/*.ts\"", "dev": "astro-scripts dev \"src/**/*.ts\"",
"t": "mocha --exit --timeout 20000 test/url-protocol.test.js",
"test": "mocha --exit --timeout 20000 test/" "test": "mocha --exit --timeout 20000 test/"
}, },
"dependencies": { "dependencies": {

View file

@ -2,6 +2,7 @@ import type { CreatePreviewServer } from 'astro';
import type http from 'node:http'; import type http from 'node:http';
import { fileURLToPath } from 'node:url'; import { fileURLToPath } from 'node:url';
import { createServer } from './http-server.js'; import { createServer } from './http-server.js';
import { getNetworkAddress } from './get-network-address.js'
import type { createExports } from './server'; import type { createExports } from './server';
const preview: CreatePreviewServer = async function ({ const preview: CreatePreviewServer = async function ({
@ -58,6 +59,10 @@ const preview: CreatePreviewServer = async function ({
return pathname; return pathname;
} }
if (!host){
host = getNetworkAddress()
}
const server = createServer( const server = createServer(
{ {
client, client,

View file

@ -5,5 +5,9 @@
"dependencies": { "dependencies": {
"astro": "workspace:*", "astro": "workspace:*",
"@astrojs/node": "workspace:*" "@astrojs/node": "workspace:*"
},
"scripts": {
"build": "astro build",
"preview": "astro preview"
} }
} }