[ci] format
This commit is contained in:
parent
5a23483efb
commit
4ee997da43
10 changed files with 33 additions and 27 deletions
|
@ -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)
|
||||
|
|
|
@ -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',
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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) => {
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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',
|
||||
|
|
|
@ -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.`
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
})
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue