From 4ee997da43e0357caaa9566de495afcf4e924803 Mon Sep 17 00:00:00 2001 From: matthewp Date: Tue, 19 Jul 2022 20:11:53 +0000 Subject: [PATCH] [ci] format --- packages/astro/src/@types/astro.ts | 2 +- packages/astro/src/core/app/index.ts | 8 ++++---- packages/astro/src/core/app/node.ts | 2 +- packages/astro/src/core/build/index.ts | 3 +-- packages/astro/src/core/build/static-build.ts | 3 +-- packages/astro/src/core/build/vite-plugin-ssr.ts | 5 +---- packages/astro/src/core/render/result.ts | 12 ++++++++---- packages/astro/src/core/request.ts | 4 ++-- packages/astro/test/client-address.test.js | 15 +++++++++------ packages/integrations/cloudflare/src/server.ts | 6 +++++- 10 files changed, 33 insertions(+), 27 deletions(-) diff --git a/packages/astro/src/@types/astro.ts b/packages/astro/src/@types/astro.ts index 3e1bfd4a8..e3e94095a 100644 --- a/packages/astro/src/@types/astro.ts +++ b/packages/astro/src/@types/astro.ts @@ -93,7 +93,7 @@ export interface AstroGlobal extends AstroGlobalPartial { */ canonicalURL: URL; /** The address (usually IP address) of the user. Used with SSR only. - * + * */ clientAddress: string; /** Parameters passed to a dynamic page generated using [getStaticPaths](https://docs.astro.build/en/reference/api-reference/#getstaticpaths) diff --git a/packages/astro/src/core/app/index.ts b/packages/astro/src/core/app/index.ts index c3cc4d705..4a15e549e 100644 --- a/packages/astro/src/core/app/index.ts +++ b/packages/astro/src/core/app/index.ts @@ -10,8 +10,8 @@ import type { RouteInfo, SSRManifest as Manifest } from './types'; import mime from 'mime'; import { call as callEndpoint } from '../endpoint/index.js'; -import { error } from '../logger/core.js'; import { consoleLogDestination } from '../logger/console.js'; +import { error } from '../logger/core.js'; import { joinPaths, prependForwardSlash } from '../path.js'; import { render } from '../render/core.js'; import { RouteCache } from '../render/route-cache.js'; @@ -125,13 +125,13 @@ export class App { request, streaming: this.#streaming, }); - + return response; - } catch(err) { + } catch (err) { error(this.#logging, 'ssr', err); return new Response(null, { status: 500, - statusText: 'Internal server error' + statusText: 'Internal server error', }); } } diff --git a/packages/astro/src/core/app/node.ts b/packages/astro/src/core/app/node.ts index 350deb211..7b6298809 100644 --- a/packages/astro/src/core/app/node.ts +++ b/packages/astro/src/core/app/node.ts @@ -15,7 +15,7 @@ function createRequestFromNodeRequest(req: IncomingMessage): Request { method: req.method || 'GET', headers: new Headers(entries), }); - if(req.socket.remoteAddress) { + if (req.socket.remoteAddress) { Reflect.set(request, clientAddressSymbol, req.socket.remoteAddress); } return request; diff --git a/packages/astro/src/core/build/index.ts b/packages/astro/src/core/build/index.ts index 90d42dd7c..131cf1442 100644 --- a/packages/astro/src/core/build/index.ts +++ b/packages/astro/src/core/build/index.ts @@ -142,13 +142,12 @@ class AstroBuilder { viteConfig, buildConfig, }); - } catch(err: unknown) { + } catch (err: unknown) { // If the build doesn't complete, still shutdown the Vite server so the process doesn't hang. await viteServer.close(); throw err; } - // Write any additionally generated assets to disk. this.timer.assetsStart = performance.now(); Object.keys(assets).map((k) => { diff --git a/packages/astro/src/core/build/static-build.ts b/packages/astro/src/core/build/static-build.ts index ce183b9cc..33acb7161 100644 --- a/packages/astro/src/core/build/static-build.ts +++ b/packages/astro/src/core/build/static-build.ts @@ -144,8 +144,7 @@ async function ssrBuild(opts: StaticBuildOptions, internals: BuildInternals, inp }), ...(viteConfig.plugins || []), // SSR needs to be last - isBuildingToSSR(opts.astroConfig) && - vitePluginSSR(internals, opts.astroConfig._ctx.adapter!), + isBuildingToSSR(opts.astroConfig) && vitePluginSSR(internals, opts.astroConfig._ctx.adapter!), vitePluginAnalyzer(opts.astroConfig, internals), ], publicDir: ssr ? false : viteConfig.publicDir, diff --git a/packages/astro/src/core/build/vite-plugin-ssr.ts b/packages/astro/src/core/build/vite-plugin-ssr.ts index feedadea2..2c3b88a11 100644 --- a/packages/astro/src/core/build/vite-plugin-ssr.ts +++ b/packages/astro/src/core/build/vite-plugin-ssr.ts @@ -19,10 +19,7 @@ const resolvedVirtualModuleId = '\0' + virtualModuleId; const manifestReplace = '@@ASTRO_MANIFEST_REPLACE@@'; const replaceExp = new RegExp(`['"](${manifestReplace})['"]`, 'g'); -export function vitePluginSSR( - internals: BuildInternals, - adapter: AstroAdapter -): VitePlugin { +export function vitePluginSSR(internals: BuildInternals, adapter: AstroAdapter): VitePlugin { return { name: '@astrojs/vite-plugin-astro-ssr', enforce: 'post', diff --git a/packages/astro/src/core/render/result.ts b/packages/astro/src/core/render/result.ts index 4b341a575..4ecf04b44 100644 --- a/packages/astro/src/core/render/result.ts +++ b/packages/astro/src/core/render/result.ts @@ -157,11 +157,15 @@ export function createResult(args: CreateResultArgs): SSRResult { __proto__: astroGlobal, canonicalURL, get clientAddress() { - if(!(clientAddressSymbol in request)) { - if(args.adapterName) { - throw new Error(`Astro.clientAddress is not available in the ${args.adapterName} adapter. File an issue with the adapter to add support.`); + if (!(clientAddressSymbol in request)) { + if (args.adapterName) { + throw new Error( + `Astro.clientAddress is not available in the ${args.adapterName} adapter. File an issue with the adapter to add support.` + ); } else { - throw new Error(`Astro.clientAddress is not available in your environment. Ensure that you are using an SSR adapter that supports this feature.`) + throw new Error( + `Astro.clientAddress is not available in your environment. Ensure that you are using an SSR adapter that supports this feature.` + ); } } diff --git a/packages/astro/src/core/request.ts b/packages/astro/src/core/request.ts index 87b95a7a8..6f356b068 100644 --- a/packages/astro/src/core/request.ts +++ b/packages/astro/src/core/request.ts @@ -71,8 +71,8 @@ export function createRequest({ return _headers; }, }); - } else if(clientAddress) { - Reflect.set(request, clientAddressSymbol, clientAddress); + } else if (clientAddress) { + Reflect.set(request, clientAddressSymbol, clientAddress); } return request; diff --git a/packages/astro/test/client-address.test.js b/packages/astro/test/client-address.test.js index 8be85cc24..c356c16eb 100644 --- a/packages/astro/test/client-address.test.js +++ b/packages/astro/test/client-address.test.js @@ -53,7 +53,7 @@ describe('Astro.clientAddress', () => { let $ = cheerio.load(html); let address = $('#address'); - // Just checking that something is here. Not specifying address as it + // Just checking that something is here. Not specifying address as it // might differ per machine. expect(address.length).to.be.greaterThan(0); }); @@ -81,7 +81,7 @@ describe('Astro.clientAddress', () => { const response = await app.render(request); expect(response.status).to.equal(500); }); - }) + }); describe('SSG', () => { /** @type {import('./test-utils').Fixture} */ @@ -98,10 +98,13 @@ describe('Astro.clientAddress', () => { try { await fixture.build(); expect(false).to.equal(true, 'Build should not have completed'); - } catch(err) { - expect(err.message).to.match(/Astro\.clientAddress/, 'Error message mentions Astro.clientAddress'); + } catch (err) { + expect(err.message).to.match( + /Astro\.clientAddress/, + 'Error message mentions Astro.clientAddress' + ); } - }) + }); }); describe('Development', () => { @@ -125,6 +128,6 @@ describe('Astro.clientAddress', () => { let res = await fixture.fetch('/'); expect(res.status).to.equal(500); }); - }) + }); }); }); diff --git a/packages/integrations/cloudflare/src/server.ts b/packages/integrations/cloudflare/src/server.ts index 07858a7ed..097f29d37 100644 --- a/packages/integrations/cloudflare/src/server.ts +++ b/packages/integrations/cloudflare/src/server.ts @@ -20,7 +20,11 @@ export function createExports(manifest: SSRManifest) { } if (app.match(request)) { - Reflect.set(request, Symbol.for('astro.clientAddress'), request.headers.get('cf-connecting-ip')); + Reflect.set( + request, + Symbol.for('astro.clientAddress'), + request.headers.get('cf-connecting-ip') + ); return app.render(request); }