diff --git a/packages/astro/src/core/app/node.ts b/packages/astro/src/core/app/node.ts index df2fa12d9a..b90a9ec8e7 100644 --- a/packages/astro/src/core/app/node.ts +++ b/packages/astro/src/core/app/node.ts @@ -63,8 +63,9 @@ export class NodeApp extends App { const protocol = req.headers['x-forwarded-proto'] ?? ('encrypted' in req.socket && req.socket.encrypted ? 'https' : 'http'); - const hostname = req.headers["x-forwarded-host"] ?? req.headers.host ?? req.headers[":authority"]; - const port = req.headers["x-forwarded-port"]; + const hostname = + req.headers['x-forwarded-host'] ?? req.headers.host ?? req.headers[':authority']; + const port = req.headers['x-forwarded-port']; const url = `${protocol}://${hostname}${port ? `:${port}` : ''}${req.url}`; const options: RequestInit = { method: req.method || 'GET', diff --git a/packages/integrations/node/test/url.test.js b/packages/integrations/node/test/url.test.js index 39d4665272..6fc0082366 100644 --- a/packages/integrations/node/test/url.test.js +++ b/packages/integrations/node/test/url.test.js @@ -1,9 +1,9 @@ import * as assert from 'node:assert/strict'; import { before, describe, it } from 'node:test'; import { TLSSocket } from 'node:tls'; +import * as cheerio from 'cheerio'; import nodejs from '../dist/index.js'; import { createRequestAndResponse, loadFixture } from './test-utils.js'; -import * as cheerio from 'cheerio'; describe('URL', () => { /** @type {import('./test-utils.js').Fixture} */ @@ -78,8 +78,8 @@ describe('URL', () => { let { req, res, text } = createRequestAndResponse({ headers: { 'X-Forwarded-Proto': 'https', - 'X-Forwarded-Host': 'abc.xyz', - 'X-Forwarded-Port': '444' + 'X-Forwarded-Host': 'abc.xyz', + 'X-Forwarded-Port': '444', }, url: '/', }); @@ -90,6 +90,6 @@ describe('URL', () => { const html = await text(); const $ = cheerio.load(html); - assert.equal($('body').text(), "https://abc.xyz:444/"); + assert.equal($('body').text(), 'https://abc.xyz:444/'); }); });