-
Notifications
You must be signed in to change notification settings - Fork 14
feat: autogenerate default allowedHosts and trustProxyHeaders #427
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
hrishikesh-k
wants to merge
27
commits into
main
Choose a base branch
from
hk/angular-22
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
63c4b60
update deps, apply prettier, change to ESM, update tests
hrishikesh-k d723b43
update ci tests to use Node 22
hrishikesh-k a41c8f4
coderabbit 1
hrishikesh-k 5228f75
remove exclude
hrishikesh-k a772d28
update lockfiles
hrishikesh-k aa3369d
lint fixes
hrishikesh-k a87042c
fix prettier config
hrishikesh-k f17a9b0
fix npm ci
hrishikesh-k 2d4a587
coderabbit 2
hrishikesh-k 0fed716
downgrade and pin angular
hrishikesh-k a4c1f7e
update engine version range to match Angular
hrishikesh-k 49f5442
fix version and readme
hrishikesh-k 8ee6796
update readme to suggest latest CLI
hrishikesh-k 1967b06
add allowedHosts and trustedProxyHeaders
hrishikesh-k 43517b0
Merge branch 'main' into hk/angular-22
hrishikesh-k e47da59
regenrate lockfiles
hrishikesh-k 65c394d
fix type for getContext
hrishikesh-k 766344a
update readme for deploy instructions
hrishikesh-k ed297f1
prevent missing env vars from failing build
hrishikesh-k 306b642
fix for loop bug
hrishikesh-k a3cb3b7
update swapped file templates
hrishikesh-k fc84504
Merge branch 'main' into hk/angular-22
hrishikesh-k 9877951
fix context potentially being undefined
hrishikesh-k 74d27cc
consolidate app-engine exports in a single file
hrishikesh-k dc29e1a
conditionally update Angular config
hrishikesh-k 846d7fc
revert pathname to request
hrishikesh-k 35aa5cb
fix typo
hrishikesh-k File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| // This is duplicating module resolution from package.json#exports | ||
| // because some module resolution settings in tsconfig.json are not honoring export maps | ||
| // https://www.typescriptlang.org/docs/handbook/modules/theory.html#module-resolution | ||
| export * from './src/context.js' | ||
| export * from './src/app-engine.js' |
This file contains hidden or 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 |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| // This is duplicating module resolution from package.json#exports | ||
| // because some module resolution settings in tsconfig.json are not honoring export maps | ||
| // https://www.typescriptlang.org/docs/handbook/modules/theory.html#module-resolution | ||
| export * from './src/context.js' | ||
| export * from './src/app-engine.js' |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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,5 @@ | ||
| import type { Context } from '@netlify/edge-functions' | ||
|
|
||
| export declare function getAllowedHosts(): string[] | ||
| export declare function getContext(): Context | undefined | ||
| export declare function getTrustProxyHeaders(): string[] |
This file contains hidden or 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,54 @@ | ||
| import { env } from 'node:process' | ||
|
|
||
| export function getAllowedHosts() { | ||
| const allowedHosts = [] | ||
| const environmentVariables = ['DEPLOY_ID', 'DEPLOY_PRIME_URL', 'DEPLOY_URL', 'SITE_ID', 'SITE_NAME', 'URL'] | ||
|
|
||
| for (const environmentVariable of environmentVariables) { | ||
| if (!env[environmentVariable] || env[environmentVariable] === 'undefined') { | ||
| console.warn( | ||
| `Missing Netlify-specific environment variable ${environmentVariable}. \`allowedHosts\` config might be incomplete.`, | ||
| ) | ||
| return allowedHosts | ||
| } | ||
| } | ||
|
|
||
| const deployPrimeUrlHostname = new URL(env.DEPLOY_PRIME_URL).hostname | ||
|
|
||
| // <subdomain>.netlify.app OR <custom-domain> | ||
| // www handling is not required as Netlify will auto-redirect | ||
| allowedHosts.push(new URL(env.URL).hostname) | ||
| // <deploy-id>--<subdomain>.netlify.app | ||
| allowedHosts.push(new URL(env.DEPLOY_URL).hostname) | ||
| // <branch-name>--<subdomain>.netlify.app or <dp-#>--<subdomain>.netlify.app (supports ADS) | ||
| allowedHosts.push(deployPrimeUrlHostname) | ||
| // <subdomain>.netlify.app | ||
| // this will be duplicated for sites without custom domain | ||
| // but it's important to have in case a site's custom domain is removed after a deploy | ||
| allowedHosts.push(`${env.SITE_NAME}.netlify.app`) | ||
| // <site-id>.netlify.app | ||
| allowedHosts.push(`${env.SITE_ID}.netlify.app`) | ||
| // <deploy-id>--<site-id>.netlify.app | ||
| allowedHosts.push(`${env.DEPLOY_ID}--${env.SITE_ID}.netlify.app`) | ||
|
|
||
| // we need to extract the branch name or the deploy preview number | ||
| // so we can add the subdomain as well as site-id specific URLs | ||
| // this would be required for sites using ADS so that | ||
| // we can add netlify.app URLs as well | ||
| if (deployPrimeUrlHostname.includes('--')) { | ||
| const [branchNameOrDpNumber] = deployPrimeUrlHostname.split('--') | ||
| allowedHosts.push(`${branchNameOrDpNumber}--${env.SITE_NAME}.netlify.app`) | ||
| allowedHosts.push(`${branchNameOrDpNumber}--${env.SITE_ID}.netlify.app`) | ||
| } | ||
|
hrishikesh-k marked this conversation as resolved.
|
||
|
|
||
| return allowedHosts | ||
| } | ||
|
|
||
| export function getContext() { | ||
| // eslint-disable-next-line no-undef | ||
| return typeof Netlify !== 'undefined' ? Netlify?.context : undefined | ||
| } | ||
|
|
||
| export function getTrustProxyHeaders() { | ||
| return ['x-forwarded-for'] | ||
| } | ||
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.