summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Emanuele Stoppa <my.burning@gmail.com> 2023-08-15 09:24:06 +0100
committerGravatar Emanuele Stoppa <my.burning@gmail.com> 2023-08-15 09:24:06 +0100
commitf1c1c99ad4b40c700d81c295efad02875f0ff782 (patch)
tree9384a6981f48d056d0fcb5ed51afa8ae16e6350f
parent578357a5ae62a56aa372820175a3de3dee1c9cdc (diff)
parent81269c66859b51ab4e4ec064e39bcb46b5783704 (diff)
downloadastro-f1c1c99ad4b40c700d81c295efad02875f0ff782.tar.gz
astro-f1c1c99ad4b40c700d81c295efad02875f0ff782.tar.zst
astro-f1c1c99ad4b40c700d81c295efad02875f0ff782.zip
Merge remote-tracking branch 'origin/main' into next
-rw-r--r--packages/integrations/node/CHANGELOG.md9
-rw-r--r--packages/integrations/node/src/get-network-address.ts48
-rw-r--r--packages/integrations/node/src/preview.ts13
-rw-r--r--packages/integrations/node/src/standalone.ts13
4 files changed, 79 insertions, 4 deletions
diff --git a/packages/integrations/node/CHANGELOG.md b/packages/integrations/node/CHANGELOG.md
index 884eb21f8..01e61307f 100644
--- a/packages/integrations/node/CHANGELOG.md
+++ b/packages/integrations/node/CHANGELOG.md
@@ -39,6 +39,15 @@
- Updated dependencies [[`1eae2e3f7`](https://github.com/withastro/astro/commit/1eae2e3f7d693c9dfe91c8ccfbe606d32bf2fb81), [`76ddef19c`](https://github.com/withastro/astro/commit/76ddef19ccab6e5f7d3a5740cd41acf10e334b38), [`9b4f70a62`](https://github.com/withastro/astro/commit/9b4f70a629f55e461759ba46f68af7097a2e9215), [`3fdf509b2`](https://github.com/withastro/astro/commit/3fdf509b2731a9b2f972d89291e57cf78d62c769), [`2f951cd40`](https://github.com/withastro/astro/commit/2f951cd403dfcc2c3ca6aae618ae3e1409516e32), [`c022a4217`](https://github.com/withastro/astro/commit/c022a4217a805d223c1494e9eda4e48bbf810388), [`67becaa58`](https://github.com/withastro/astro/commit/67becaa580b8f787df58de66b7008b7098f1209c), [`bc37331d8`](https://github.com/withastro/astro/commit/bc37331d8154e3e95a8df9131e4e014e78a7a9e7), [`dfc2d93e3`](https://github.com/withastro/astro/commit/dfc2d93e3c645995379358fabbdfa9aab99f43d8), [`3dc1ca2fa`](https://github.com/withastro/astro/commit/3dc1ca2fac8d9965cc5085a5d09e72ed87b4281a), [`1be84dfee`](https://github.com/withastro/astro/commit/1be84dfee3ce8e6f5cc624f99aec4e980f6fde37), [`35f01df79`](https://github.com/withastro/astro/commit/35f01df797d23315f2bee2fc3fd795adb0559c58), [`3fdf509b2`](https://github.com/withastro/astro/commit/3fdf509b2731a9b2f972d89291e57cf78d62c769), [`78de801f2`](https://github.com/withastro/astro/commit/78de801f21fd4ca1653950027d953bf08614566b), [`59d6e569f`](https://github.com/withastro/astro/commit/59d6e569f63e175c97e82e94aa7974febfb76f7c), [`7723c4cc9`](https://github.com/withastro/astro/commit/7723c4cc93298c2e6530e55da7afda048f22cf81), [`fb5cd6b56`](https://github.com/withastro/astro/commit/fb5cd6b56dc27a71366ed5e1ab8bfe9b8f96bac5), [`631b9c410`](https://github.com/withastro/astro/commit/631b9c410d5d66fa384674027ba95d69ebb5063f)]:
- astro@3.0.0-beta.0
+## 5.3.3
+
+### Patch Changes
+
+- [#6928](https://github.com/withastro/astro/pull/6928) [`b16cb787f`](https://github.com/withastro/astro/commit/b16cb787fd16ebaaf860d8bb183789caf01c0fb7) Thanks [@JerryWu1234](https://github.com/JerryWu1234)! - Support the `--host` flag when running the standalone server (also works for `astro preview --host`)
+
+- Updated dependencies [[`1b8d30209`](https://github.com/withastro/astro/commit/1b8d3020990130dabfaaf753db73a32c6e0c896a), [`405913cdf`](https://github.com/withastro/astro/commit/405913cdf20b26407aa351c090f0a0859a4e6f54), [`87d4b1843`](https://github.com/withastro/astro/commit/87d4b18437c7565c48cad4bea81831c2a244ebb8), [`c23377caa`](https://github.com/withastro/astro/commit/c23377caafbc75deb91c33b9678c1b6868ad40ea), [`86bee2812`](https://github.com/withastro/astro/commit/86bee2812185df6e14025e5962a335f51853587b)]:
+ - astro@2.10.6
+
## 5.3.2
### Patch Changes
diff --git a/packages/integrations/node/src/get-network-address.ts b/packages/integrations/node/src/get-network-address.ts
new file mode 100644
index 000000000..3834c7617
--- /dev/null
+++ b/packages/integrations/node/src/get-network-address.ts
@@ -0,0 +1,48 @@
+import os from 'os';
+interface NetworkAddressOpt {
+ local: string[];
+ network: string[];
+}
+
+const wildcardHosts = new Set(['0.0.0.0', '::', '0000:0000:0000:0000:0000:0000:0000:0000']);
+type Protocol = 'http' | 'https';
+
+// this code from vite https://github.com/vitejs/vite/blob/d09bbd093a4b893e78f0bbff5b17c7cf7821f403/packages/vite/src/node/utils.ts#L892-L914
+export function getNetworkAddress(
+ protocol: Protocol = 'http',
+ hostname: string | undefined,
+ port: number,
+ base?: string
+) {
+ const NetworkAddress: NetworkAddressOpt = {
+ local: [],
+ network: [],
+ };
+ Object.values(os.networkInterfaces())
+ .flatMap((nInterface) => nInterface ?? [])
+ .filter(
+ (detail) =>
+ detail &&
+ detail.address &&
+ (detail.family === 'IPv4' ||
+ // @ts-expect-error Node 18.0 - 18.3 returns number
+ detail.family === 4)
+ )
+ .forEach((detail) => {
+ let host = detail.address.replace(
+ '127.0.0.1',
+ hostname === undefined || wildcardHosts.has(hostname) ? 'localhost' : hostname
+ );
+ // ipv6 host
+ if (host.includes(':')) {
+ host = `[${host}]`;
+ }
+ const url = `${protocol}://${host}:${port}${base ? base : ''}`;
+ if (detail.address.includes('127.0.0.1')) {
+ NetworkAddress.local.push(url);
+ } else {
+ NetworkAddress.network.push(url);
+ }
+ });
+ return NetworkAddress;
+}
diff --git a/packages/integrations/node/src/preview.ts b/packages/integrations/node/src/preview.ts
index 92f9b86ba..4a4db4632 100644
--- a/packages/integrations/node/src/preview.ts
+++ b/packages/integrations/node/src/preview.ts
@@ -1,6 +1,7 @@
import type { CreatePreviewServer } from 'astro';
import type http from 'node:http';
import { fileURLToPath } from 'node:url';
+import { getNetworkAddress } from './get-network-address.js';
import { createServer } from './http-server.js';
import type { createExports } from './server';
@@ -67,9 +68,17 @@ const preview: CreatePreviewServer = async function ({
},
handler
);
+ const address = getNetworkAddress('http', host, port);
- // eslint-disable-next-line no-console
- console.log(`Preview server listening on http://${host}:${port}`);
+ if (host === undefined) {
+ // eslint-disable-next-line no-console
+ console.log(
+ `Preview server listening on \n local: ${address.local[0]} \t\n network: ${address.network[0]}\n`
+ );
+ } else {
+ // eslint-disable-next-line no-console
+ console.log(`Preview server listening on ${address.local[0]}`);
+ }
return server;
};
diff --git a/packages/integrations/node/src/standalone.ts b/packages/integrations/node/src/standalone.ts
index 68b2cebcd..94dc26758 100644
--- a/packages/integrations/node/src/standalone.ts
+++ b/packages/integrations/node/src/standalone.ts
@@ -2,6 +2,7 @@ import type { NodeApp } from 'astro/app/node';
import https from 'https';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
+import { getNetworkAddress } from './get-network-address.js';
import { createServer } from './http-server.js';
import middleware from './nodeMiddleware.js';
import type { Options } from './types';
@@ -55,9 +56,17 @@ export default function startServer(app: NodeApp, options: Options) {
);
const protocol = server.server instanceof https.Server ? 'https' : 'http';
+ const address = getNetworkAddress(protocol, host, port);
- // eslint-disable-next-line no-console
- console.log(`Server listening on ${protocol}://${host}:${port}`);
+ if (host === undefined) {
+ // eslint-disable-next-line no-console
+ console.log(
+ `Preview server listening on \n local: ${address.local[0]} \t\n network: ${address.network[0]}\n`
+ );
+ } else {
+ // eslint-disable-next-line no-console
+ console.log(`Preview server listening on ${address.local[0]}`);
+ }
return {
server,