diff options
Diffstat (limited to 'packages/integrations/node/src')
-rw-r--r-- | packages/integrations/node/src/index.ts | 2 | ||||
-rw-r--r-- | packages/integrations/node/src/log-listening-on.ts | 17 | ||||
-rw-r--r-- | packages/integrations/node/src/middleware.ts | 4 | ||||
-rw-r--r-- | packages/integrations/node/src/preview.ts | 10 | ||||
-rw-r--r-- | packages/integrations/node/src/serve-app.ts | 2 | ||||
-rw-r--r-- | packages/integrations/node/src/serve-static.ts | 12 | ||||
-rw-r--r-- | packages/integrations/node/src/standalone.ts | 3 |
7 files changed, 35 insertions, 15 deletions
diff --git a/packages/integrations/node/src/index.ts b/packages/integrations/node/src/index.ts index 36d9ee30f..eb3c98a9b 100644 --- a/packages/integrations/node/src/index.ts +++ b/packages/integrations/node/src/index.ts @@ -73,7 +73,7 @@ export default function createIntegration(userOptions: UserOptions): AstroIntegr if (config.output === 'static') { logger.warn( - `\`output: "server"\` or \`output: "hybrid"\` is required to use this adapter.`, + `\`output: "server"\` or \`output: "hybrid"\` is required to use this adapter.` ); } }, diff --git a/packages/integrations/node/src/log-listening-on.ts b/packages/integrations/node/src/log-listening-on.ts index 7e299740c..2f774c31c 100644 --- a/packages/integrations/node/src/log-listening-on.ts +++ b/packages/integrations/node/src/log-listening-on.ts @@ -8,20 +8,20 @@ import type { Options } from './types.js'; export async function logListeningOn( logger: AstroIntegrationLogger, server: http.Server | https.Server, - options: Pick<Options, 'host'>, + options: Pick<Options, 'host'> ) { await new Promise<void>((resolve) => server.once('listening', resolve)); const protocol = server instanceof https.Server ? 'https' : 'http'; // Allow to provide host value at runtime const host = getResolvedHostForHttpServer( - process.env.HOST !== undefined && process.env.HOST !== '' ? process.env.HOST : options.host, + process.env.HOST !== undefined && process.env.HOST !== '' ? process.env.HOST : options.host ); const { port } = server.address() as AddressInfo; const address = getNetworkAddress(protocol, host, port); if (host === undefined) { logger.info( - `Server listening on \n local: ${address.local[0]} \t\n network: ${address.network[0]}\n`, + `Server listening on \n local: ${address.local[0]} \t\n network: ${address.network[0]}\n` ); } else { logger.info(`Server listening on ${address.local[0]}`); @@ -32,9 +32,11 @@ function getResolvedHostForHttpServer(host: string | boolean) { if (host === false) { // Use a secure default return 'localhost'; + // biome-ignore lint/style/noUselessElse: <explanation> } else if (host === true) { // If passed --host in the CLI without arguments return undefined; // undefined typically means 0.0.0.0 or :: (listen on all IPs) + // biome-ignore lint/style/noUselessElse: <explanation> } else { return host; } @@ -49,29 +51,32 @@ const wildcardHosts = new Set(['0.0.0.0', '::', '0000:0000:0000:0000:0000:0000:0 // this code from vite https://github.com/vitejs/vite/blob/d09bbd093a4b893e78f0bbff5b17c7cf7821f403/packages/vite/src/node/utils.ts#L892-L914 export function getNetworkAddress( + // biome-ignore lint/style/useDefaultParameterLast: <explanation> protocol: 'http' | 'https' = 'http', hostname: string | undefined, port: number, - base?: string, + base?: string ) { const NetworkAddress: NetworkAddressOpt = { local: [], network: [], }; + // biome-ignore lint/complexity/noForEach: <explanation> Object.values(os.networkInterfaces()) .flatMap((nInterface) => nInterface ?? []) .filter( (detail) => + // biome-ignore lint/complexity/useOptionalChain: <explanation> detail && 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, + hostname === undefined || wildcardHosts.has(hostname) ? 'localhost' : hostname ); // ipv6 host if (host.includes(':')) { diff --git a/packages/integrations/node/src/middleware.ts b/packages/integrations/node/src/middleware.ts index 5cc4c4a46..5bb104914 100644 --- a/packages/integrations/node/src/middleware.ts +++ b/packages/integrations/node/src/middleware.ts @@ -15,7 +15,7 @@ export default function createMiddleware(app: NodeApp): RequestHandler { const logger = app.getAdapterLogger(); // using spread args because express trips up if the function's // stringified body includes req, res, next, locals directly - return async function (...args) { + return async (...args) => { // assume normal invocation at first const [req, res, next, locals] = args; // short circuit if it is an error invocation @@ -23,6 +23,7 @@ export default function createMiddleware(app: NodeApp): RequestHandler { const error = req; if (next) { return next(error); + // biome-ignore lint/style/noUselessElse: <explanation> } else { throw error; } @@ -33,6 +34,7 @@ export default function createMiddleware(app: NodeApp): RequestHandler { logger.error(`Could not render ${req.url}`); console.error(err); if (!res.headersSent) { + // biome-ignore lint/style/noUnusedTemplateLiteral: <explanation> res.writeHead(500, `Server error`); res.end(); } diff --git a/packages/integrations/node/src/preview.ts b/packages/integrations/node/src/preview.ts index 518155c4a..7e9415df8 100644 --- a/packages/integrations/node/src/preview.ts +++ b/packages/integrations/node/src/preview.ts @@ -8,7 +8,7 @@ import { createServer } from './standalone.js'; type ServerModule = ReturnType<typeof createExports>; type MaybeServerModule = Partial<ServerModule>; -const createPreviewServer: CreatePreviewServer = async function (preview) { +const createPreviewServer: CreatePreviewServer = async (preview) => { let ssrHandler: ServerModule['handler']; let options: ServerModule['options']; try { @@ -16,19 +16,21 @@ const createPreviewServer: CreatePreviewServer = async function (preview) { const ssrModule: MaybeServerModule = await import(preview.serverEntrypoint.toString()); if (typeof ssrModule.handler === 'function') { ssrHandler = ssrModule.handler; + // biome-ignore lint/style/noNonNullAssertion: <explanation> options = ssrModule.options!; } else { throw new AstroError( - `The server entrypoint doesn't have a handler. Are you sure this is the right file?`, + `The server entrypoint doesn't have a handler. Are you sure this is the right file?` ); } } catch (err) { if ((err as any).code === 'ERR_MODULE_NOT_FOUND') { throw new AstroError( `The server entrypoint ${fileURLToPath( - preview.serverEntrypoint, - )} does not exist. Have you ran a build yet?`, + preview.serverEntrypoint + )} does not exist. Have you ran a build yet?` ); + // biome-ignore lint/style/noUselessElse: <explanation> } else { throw err; } diff --git a/packages/integrations/node/src/serve-app.ts b/packages/integrations/node/src/serve-app.ts index 72b4e0fd6..2934a01ab 100644 --- a/packages/integrations/node/src/serve-app.ts +++ b/packages/integrations/node/src/serve-app.ts @@ -39,7 +39,7 @@ export function createAppHandler(app: NodeApp): RequestHandler { addCookieHeader: true, locals, routeData, - }), + }) ); await NodeApp.writeResponse(response, res); } else if (next) { diff --git a/packages/integrations/node/src/serve-static.ts b/packages/integrations/node/src/serve-static.ts index 725f7afa6..9221594d7 100644 --- a/packages/integrations/node/src/serve-static.ts +++ b/packages/integrations/node/src/serve-static.ts @@ -29,23 +29,28 @@ export function createStaticHandler(app: NodeApp, options: Options) { let isDirectory = false; try { isDirectory = fs.lstatSync(filePath).isDirectory(); - } catch {} + } catch { } const { trailingSlash = 'ignore' } = options; const hasSlash = urlPath.endsWith('/'); switch (trailingSlash) { case 'never': + // biome-ignore lint/suspicious/noDoubleEquals: <explanation> if (isDirectory && urlPath != '/' && hasSlash) { + // biome-ignore lint/style/useTemplate: <explanation> + // biome-ignore lint/suspicious/noFallthroughSwitchClause: <explanation> pathname = urlPath.slice(0, -1) + (urlQuery ? '?' + urlQuery : ''); res.statusCode = 301; res.setHeader('Location', pathname); return res.end(); + // biome-ignore lint/style/noUselessElse: <explanation> } else pathname = urlPath; // intentionally fall through case 'ignore': { if (isDirectory && !hasSlash) { + // biome-ignore lint/style/useTemplate: <explanation> pathname = urlPath + '/index.html'; } else pathname = urlPath; } @@ -53,10 +58,12 @@ export function createStaticHandler(app: NodeApp, options: Options) { case 'always': // trailing slash is not added to "subresources" if (!hasSlash && !isSubresourceRegex.test(urlPath)) { + // biome-ignore lint/style/useTemplate: <explanation> pathname = urlPath + '/' + (urlQuery ? '?' + urlQuery : ''); res.statusCode = 301; res.setHeader('Location', pathname); return res.end(); + // biome-ignore lint/style/noUselessElse: <explanation> } else pathname = urlPath; break; } @@ -110,6 +117,7 @@ function resolveClientDir(options: Options) { while (!serverEntryFolderURL.endsWith(serverFolder)) { serverEntryFolderURL = path.dirname(serverEntryFolderURL); } + // biome-ignore lint/style/useTemplate: <explanation> const serverEntryURL = serverEntryFolderURL + '/entry.mjs'; const clientURL = new URL(appendForwardSlash(rel), serverEntryURL); const client = url.fileURLToPath(clientURL); @@ -117,9 +125,11 @@ function resolveClientDir(options: Options) { } function prependForwardSlash(pth: string) { + // biome-ignore lint/style/useTemplate: <explanation> return pth.startsWith('/') ? pth : '/' + pth; } function appendForwardSlash(pth: string) { + // biome-ignore lint/style/useTemplate: <explanation> return pth.endsWith('/') ? pth : pth + '/'; } diff --git a/packages/integrations/node/src/standalone.ts b/packages/integrations/node/src/standalone.ts index 76e672d2f..8ae10a9ba 100644 --- a/packages/integrations/node/src/standalone.ts +++ b/packages/integrations/node/src/standalone.ts @@ -39,6 +39,7 @@ export function createStandaloneHandler(app: NodeApp, options: Options) { return (req: http.IncomingMessage, res: http.ServerResponse) => { try { // validate request path + // biome-ignore lint/style/noNonNullAssertion: <explanation> decodeURI(req.url!); } catch { res.writeHead(400); @@ -59,7 +60,7 @@ export function createServer(listener: http.RequestListener, host: string, port: key: fs.readFileSync(process.env.SERVER_KEY_PATH), cert: fs.readFileSync(process.env.SERVER_CERT_PATH), }, - listener, + listener ); } else { httpServer = http.createServer(listener); |