-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix
Astro.url.protocol
when using the @astrojs/node SSR adapter wit…
…h HTTPS
- Loading branch information
Showing
7 changed files
with
116 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
'astro': patch | ||
'@astrojs/node': patch | ||
--- | ||
|
||
Fix `Astro.url.protocol` when using the @astrojs/node SSR adapter with HTTPS |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
packages/integrations/node/test/fixtures/url-protocol/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"name": "@test/url-protocol", | ||
"version": "0.0.0", | ||
"private": true, | ||
"dependencies": { | ||
"astro": "workspace:*", | ||
"@astrojs/node": "workspace:*" | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
packages/integrations/node/test/fixtures/url-protocol/src/pages/index.astro
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
--- | ||
--- | ||
|
||
<html lang="en"> | ||
<head> | ||
<title>url-protocol</title> | ||
</head> | ||
<body> | ||
{Astro.url.protocol} | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import { TLSSocket } from 'tls'; | ||
import nodejs from '../dist/index.js'; | ||
import { loadFixture, createRequestAndResponse } from './test-utils.js'; | ||
import { expect } from 'chai'; | ||
|
||
describe('URL protocol', () => { | ||
/** @type {import('./test-utils').Fixture} */ | ||
let fixture; | ||
|
||
before(async () => { | ||
fixture = await loadFixture({ | ||
root: './fixtures/url-protocol/', | ||
output: 'server', | ||
adapter: nodejs({ mode: 'standalone' }), | ||
}); | ||
await fixture.build(); | ||
}); | ||
|
||
it('return http when non-secure', async () => { | ||
const { handler } = await import('./fixtures/url-protocol/dist/server/entry.mjs'); | ||
let { req, res, text } = createRequestAndResponse({ | ||
url: '/', | ||
}); | ||
|
||
handler(req, res); | ||
req.send(); | ||
|
||
const html = await text(); | ||
expect(html).to.include('http:'); | ||
}); | ||
|
||
it('return https when secure', async () => { | ||
const { handler } = await import('./fixtures/url-protocol/dist/server/entry.mjs'); | ||
let { req, res, text } = createRequestAndResponse({ | ||
socket: new TLSSocket(), | ||
url: '/', | ||
}); | ||
|
||
handler(req, res); | ||
req.send(); | ||
|
||
const html = await text(); | ||
expect(html).to.include('https:'); | ||
}); | ||
|
||
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'); | ||
let { req, res, text } = createRequestAndResponse({ | ||
headers: { 'X-Forwarded-Proto': 'http' }, | ||
url: '/', | ||
}); | ||
|
||
handler(req, res); | ||
req.send(); | ||
|
||
const html = await text(); | ||
expect(html).to.include('http:'); | ||
}); | ||
|
||
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'); | ||
let { req, res, text } = createRequestAndResponse({ | ||
headers: { 'X-Forwarded-Proto': 'https' }, | ||
url: '/', | ||
}); | ||
|
||
handler(req, res); | ||
req.send(); | ||
|
||
const html = await text(); | ||
expect(html).to.include('https:'); | ||
}); | ||
}); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.