summaryrefslogtreecommitdiff
path: root/packages/integrations/node
diff options
context:
space:
mode:
authorGravatar natemoo-re <natemoo-re@users.noreply.github.com> 2023-08-10 18:25:25 +0000
committerGravatar astrobot-houston <fred+astrobot@astro.build> 2023-08-10 18:25:25 +0000
commit493c6dda50e3fc5a4476a7eb3343947e903c7334 (patch)
treeef3858aa8c634db6278fee27073540e56bc14bed /packages/integrations/node
parent101af57dc7c8410ac89102e60a1f8d59a4183f6c (diff)
downloadastro-493c6dda50e3fc5a4476a7eb3343947e903c7334.tar.gz
astro-493c6dda50e3fc5a4476a7eb3343947e903c7334.tar.zst
astro-493c6dda50e3fc5a4476a7eb3343947e903c7334.zip
[ci] format
Diffstat (limited to 'packages/integrations/node')
-rw-r--r--packages/integrations/node/src/get-network-address.ts44
-rw-r--r--packages/integrations/node/src/preview.ts9
-rw-r--r--packages/integrations/node/src/standalone.ts7
3 files changed, 33 insertions, 27 deletions
diff --git a/packages/integrations/node/src/get-network-address.ts b/packages/integrations/node/src/get-network-address.ts
index 7d9f89a28..3834c7617 100644
--- a/packages/integrations/node/src/get-network-address.ts
+++ b/packages/integrations/node/src/get-network-address.ts
@@ -1,22 +1,23 @@
-import os from 'os'
+import os from 'os';
interface NetworkAddressOpt {
- local: string[]
- network: string[]
+ local: string[];
+ network: string[];
}
-const wildcardHosts = new Set([
- '0.0.0.0',
- '::',
- '0000:0000:0000:0000:0000:0000:0000:0000',
-])
-type Protocol = 'http' | 'https'
+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) {
+export function getNetworkAddress(
+ protocol: Protocol = 'http',
+ hostname: string | undefined,
+ port: number,
+ base?: string
+) {
const NetworkAddress: NetworkAddressOpt = {
local: [],
- network: []
- }
+ network: [],
+ };
Object.values(os.networkInterfaces())
.flatMap((nInterface) => nInterface ?? [])
.filter(
@@ -25,20 +26,23 @@ export function getNetworkAddress(protocol: Protocol = 'http', hostname: string
detail.address &&
(detail.family === 'IPv4' ||
// @ts-expect-error Node 18.0 - 18.3 returns number
- detail.family === 4),
+ detail.family === 4)
)
.forEach((detail) => {
- let host = detail.address.replace('127.0.0.1', hostname === undefined || wildcardHosts.has(hostname) ? 'localhost' : hostname)
+ let host = detail.address.replace(
+ '127.0.0.1',
+ hostname === undefined || wildcardHosts.has(hostname) ? 'localhost' : hostname
+ );
// ipv6 host
if (host.includes(':')) {
- host = `[${host}]`
+ host = `[${host}]`;
}
- const url = `${protocol}://${host}:${port}${base ? base : ''}`
+ const url = `${protocol}://${host}:${port}${base ? base : ''}`;
if (detail.address.includes('127.0.0.1')) {
- NetworkAddress.local.push(url)
+ NetworkAddress.local.push(url);
} else {
- NetworkAddress.network.push(url)
+ NetworkAddress.network.push(url);
}
- })
- return NetworkAddress
+ });
+ return NetworkAddress;
}
diff --git a/packages/integrations/node/src/preview.ts b/packages/integrations/node/src/preview.ts
index fdf2a5cbb..4a4db4632 100644
--- a/packages/integrations/node/src/preview.ts
+++ b/packages/integrations/node/src/preview.ts
@@ -1,8 +1,8 @@
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 { getNetworkAddress } from './get-network-address.js'
import type { createExports } from './server';
const preview: CreatePreviewServer = async function ({
@@ -68,17 +68,18 @@ const preview: CreatePreviewServer = async function ({
},
handler
);
- const address = getNetworkAddress('http', host, port)
+ const address = getNetworkAddress('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`);
+ 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 ff1a0f693..94dc26758 100644
--- a/packages/integrations/node/src/standalone.ts
+++ b/packages/integrations/node/src/standalone.ts
@@ -2,9 +2,9 @@ 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 { getNetworkAddress } from './get-network-address.js'
import type { Options } from './types';
function resolvePaths(options: Options) {
@@ -56,12 +56,13 @@ export default function startServer(app: NodeApp, options: Options) {
);
const protocol = server.server instanceof https.Server ? 'https' : 'http';
- const address = getNetworkAddress(protocol, host, port)
+ const address = getNetworkAddress(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`);
+ `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]}`);