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) {
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), '/');
}

View file

@ -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": {

View file

@ -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,

View file

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