sumbit test code
This commit is contained in:
parent
bb0b0169c7
commit
31f822e27d
5 changed files with 12 additions and 5 deletions
|
@ -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), '/');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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": {
|
||||||
|
|
|
@ -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,
|
||||||
|
@ -67,7 +72,7 @@ const preview: CreatePreviewServer = async function ({
|
||||||
},
|
},
|
||||||
handler
|
handler
|
||||||
);
|
);
|
||||||
|
|
||||||
// eslint-disable-next-line no-console
|
// eslint-disable-next-line no-console
|
||||||
console.log(`Preview server listening on http://${host}:${port}`);
|
console.log(`Preview server listening on http://${host}:${port}`);
|
||||||
|
|
||||||
|
|
|
@ -5,5 +5,9 @@
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"astro": "workspace:*",
|
"astro": "workspace:*",
|
||||||
"@astrojs/node": "workspace:*"
|
"@astrojs/node": "workspace:*"
|
||||||
|
},
|
||||||
|
"scripts": {
|
||||||
|
"build": "astro build",
|
||||||
|
"preview": "astro preview"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue