aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Arsh <69170106+lilnasy@users.noreply.github.com> 2024-04-03 18:57:23 +0530
committerGravatar GitHub <noreply@github.com> 2024-04-03 18:57:23 +0530
commit68817f7a0036ec6e42a3c39d16c9adbdd460ae9a (patch)
tree890ad052d252eecd19b05791c693f309824e9388
parent0310a1f3f3ea9e67a8d4753f4779e33037a0533c (diff)
downloadastro-68817f7a0036ec6e42a3c39d16c9adbdd460ae9a.tar.gz
astro-68817f7a0036ec6e42a3c39d16c9adbdd460ae9a.tar.zst
astro-68817f7a0036ec6e42a3c39d16c9adbdd460ae9a.zip
fix(app/node): include `x-forwarded-port` header in url (#10666)
* fix(app/node): include `x-forwarded-port` header in url * add changeset * add test
-rw-r--r--packages/integrations/node/test/fixtures/url-protocol/src/pages/index.astro11
-rw-r--r--packages/integrations/node/test/fixtures/url/package.json (renamed from packages/integrations/node/test/fixtures/url-protocol/package.json)2
-rw-r--r--packages/integrations/node/test/fixtures/url/src/pages/index.astro9
-rw-r--r--packages/integrations/node/test/url.test.js (renamed from packages/integrations/node/test/url-protocol.test.js)35
4 files changed, 38 insertions, 19 deletions
diff --git a/packages/integrations/node/test/fixtures/url-protocol/src/pages/index.astro b/packages/integrations/node/test/fixtures/url-protocol/src/pages/index.astro
deleted file mode 100644
index 61fb9867b..000000000
--- a/packages/integrations/node/test/fixtures/url-protocol/src/pages/index.astro
+++ /dev/null
@@ -1,11 +0,0 @@
----
----
-
-<html lang="en">
- <head>
- <title>url-protocol</title>
- </head>
- <body>
- {Astro.url.protocol}
- </body>
-</html>
diff --git a/packages/integrations/node/test/fixtures/url-protocol/package.json b/packages/integrations/node/test/fixtures/url/package.json
index 4b0775716..f349011fd 100644
--- a/packages/integrations/node/test/fixtures/url-protocol/package.json
+++ b/packages/integrations/node/test/fixtures/url/package.json
@@ -1,5 +1,5 @@
{
- "name": "@test/url-protocol",
+ "name": "@test/url",
"version": "0.0.0",
"private": true,
"dependencies": {
diff --git a/packages/integrations/node/test/fixtures/url/src/pages/index.astro b/packages/integrations/node/test/fixtures/url/src/pages/index.astro
new file mode 100644
index 000000000..003429f52
--- /dev/null
+++ b/packages/integrations/node/test/fixtures/url/src/pages/index.astro
@@ -0,0 +1,9 @@
+---
+---
+
+<html lang="en">
+ <head>
+ <title>URL</title>
+ </head>
+ <body>{Astro.url.href}</body>
+</html>
diff --git a/packages/integrations/node/test/url-protocol.test.js b/packages/integrations/node/test/url.test.js
index 94d53104b..39d466527 100644
--- a/packages/integrations/node/test/url-protocol.test.js
+++ b/packages/integrations/node/test/url.test.js
@@ -3,14 +3,15 @@ import { before, describe, it } from 'node:test';
import { TLSSocket } from 'node:tls';
import nodejs from '../dist/index.js';
import { createRequestAndResponse, loadFixture } from './test-utils.js';
+import * as cheerio from 'cheerio';
-describe('URL protocol', () => {
- /** @type {import('./test-utils').Fixture} */
+describe('URL', () => {
+ /** @type {import('./test-utils.js').Fixture} */
let fixture;
before(async () => {
fixture = await loadFixture({
- root: './fixtures/url-protocol/',
+ root: './fixtures/url/',
output: 'server',
adapter: nodejs({ mode: 'standalone' }),
});
@@ -18,7 +19,7 @@ describe('URL protocol', () => {
});
it('return http when non-secure', async () => {
- const { handler } = await import('./fixtures/url-protocol/dist/server/entry.mjs');
+ const { handler } = await import('./fixtures/url/dist/server/entry.mjs');
let { req, res, text } = createRequestAndResponse({
url: '/',
});
@@ -31,7 +32,7 @@ describe('URL protocol', () => {
});
it('return https when secure', async () => {
- const { handler } = await import('./fixtures/url-protocol/dist/server/entry.mjs');
+ const { handler } = await import('./fixtures/url/dist/server/entry.mjs');
let { req, res, text } = createRequestAndResponse({
socket: new TLSSocket(),
url: '/',
@@ -45,7 +46,7 @@ describe('URL protocol', () => {
});
it('return http when the X-Forwarded-Proto header is set to http', async () => {
- const { handler } = await import('./fixtures/url-protocol/dist/server/entry.mjs');
+ const { handler } = await import('./fixtures/url/dist/server/entry.mjs');
let { req, res, text } = createRequestAndResponse({
headers: { 'X-Forwarded-Proto': 'http' },
url: '/',
@@ -59,7 +60,7 @@ describe('URL protocol', () => {
});
it('return https when the X-Forwarded-Proto header is set to https', async () => {
- const { handler } = await import('./fixtures/url-protocol/dist/server/entry.mjs');
+ const { handler } = await import('./fixtures/url/dist/server/entry.mjs');
let { req, res, text } = createRequestAndResponse({
headers: { 'X-Forwarded-Proto': 'https' },
url: '/',
@@ -71,4 +72,24 @@ describe('URL protocol', () => {
const html = await text();
assert.equal(html.includes('https:'), true);
});
+
+ it('includes forwarded host and port in the url', async () => {
+ const { handler } = await import('./fixtures/url/dist/server/entry.mjs');
+ let { req, res, text } = createRequestAndResponse({
+ headers: {
+ 'X-Forwarded-Proto': 'https',
+ 'X-Forwarded-Host': 'abc.xyz',
+ 'X-Forwarded-Port': '444'
+ },
+ url: '/',
+ });
+
+ handler(req, res);
+ req.send();
+
+ const html = await text();
+ const $ = cheerio.load(html);
+
+ assert.equal($('body').text(), "https://abc.xyz:444/");
+ });
});