0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2024-12-30 22:03:56 -05:00

[ci] format

This commit is contained in:
Jan Havlena 2024-10-09 09:36:51 +00:00 committed by astrobot-houston
parent e96bcae535
commit 116c533596
2 changed files with 4 additions and 4 deletions

View file

@ -84,10 +84,11 @@ export class NodeApp extends App {
// @example "443,8080,80" => "443" // @example "443,8080,80" => "443"
const forwardedPort = getFirstForwardedValue(req.headers['x-forwarded-port']); const forwardedPort = getFirstForwardedValue(req.headers['x-forwarded-port']);
const port = forwardedPort ?? req.socket?.remotePort?.toString() ?? (isEncrypted ? '443' : '80'); const port =
forwardedPort ?? req.socket?.remotePort?.toString() ?? (isEncrypted ? '443' : '80');
const portInHostname = typeof hostname === 'string' && /:\d+$/.test(hostname); const portInHostname = typeof hostname === 'string' && /:\d+$/.test(hostname);
const hostnamePort = portInHostname ? hostname : `${hostname}:${port}` const hostnamePort = portInHostname ? hostname : `${hostname}:${port}`;
const url = `${protocol}://${hostnamePort}${req.url}`; const url = `${protocol}://${hostnamePort}${req.url}`;
const options: RequestInit = { const options: RequestInit = {
@ -105,7 +106,7 @@ export class NodeApp extends App {
// @example "1.1.1.1,8.8.8.8" => "1.1.1.1" // @example "1.1.1.1,8.8.8.8" => "1.1.1.1"
const forwardedClientIp = getFirstForwardedValue(req.headers['x-forwarded-for']); const forwardedClientIp = getFirstForwardedValue(req.headers['x-forwarded-for']);
const clientIp = forwardedClientIp || req.socket?.remoteAddress; const clientIp = forwardedClientIp || req.socket?.remoteAddress;
if (clientIp) { if (clientIp) {
Reflect.set(request, clientAddressSymbol, clientIp); Reflect.set(request, clientAddressSymbol, clientIp);
} }

View file

@ -158,7 +158,6 @@ describe('NodeApp', () => {
assert.equal(result.url, 'https://example.com:3000/'); assert.equal(result.url, 'https://example.com:3000/');
}); });
it('prefers port from x-forwarded-host', () => { it('prefers port from x-forwarded-host', () => {
const result = NodeApp.createRequest({ const result = NodeApp.createRequest({
...mockNodeRequest, ...mockNodeRequest,