-
-
Notifications
You must be signed in to change notification settings - Fork 15
feat: rewrite redirects sent through the proxy #139
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
mattmess1221
wants to merge
9
commits into
johannschopplich:main
Choose a base branch
from
mattmess1221:feat/rewrite-proxy-redirects
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
9 commits
Select commit
Hold shift + click to select a range
651341a
feat: rewrite redirects sent through the proxy
mattmess1221 cd273b4
fix: check for outside locations without host
mattmess1221 bd118c4
fix: ensure protocol matches when checking same origin
mattmess1221 9c96f2b
fix: tests
mattmess1221 9cda09b
fix: imports
mattmess1221 54cc9d4
fix: improve jsdocs, change 500 error to 502
mattmess1221 33e594c
fix: update error code in cleanRedirectLocation function from 500 to 502
mattmess1221 2a5b639
fix: update export declarations in types.d.ts for consistency
mattmess1221 719cabc
fix: update error code in redirect test from 500 to 502
mattmess1221 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 |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| import { defineEventHandler } from 'h3' | ||
|
|
||
| export default defineEventHandler(async (event) => { | ||
| return { | ||
| method: event.node.req.method, | ||
| url: event.node.req.url, | ||
| headers: event.node.req.headers, | ||
| } | ||
| }) |
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,8 @@ | ||
| import { defineEventHandler, getQuery } from 'h3' | ||
|
|
||
| // clone of httpbin.org/redirect | ||
| export default defineEventHandler<{ query: { url: string, status_code?: number } }>(async (event) => { | ||
| const { url, status_code = 302 } = getQuery(event) | ||
| event.node.res.statusCode = Number(status_code) | ||
| event.node.res.setHeader('location', url) | ||
| }) |
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
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,11 @@ | ||
| declare module '#nuxt-api-party.nitro-config' { | ||
| export const experimentalRewriteProxyRedirects: boolean | ||
| } | ||
|
|
||
| declare module '#build/module/nuxt-api-party.config' { | ||
| export const allowClient: boolean | 'allow' | 'always' | ||
| export const serverBasePath: string | ||
|
|
||
| export const experimentalEnablePrefixedProxy: boolean | ||
| export const experimentalDisableClientPayloadCache: boolean | ||
| } |
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,17 @@ | ||
| import { defineEventHandler, getQuery, getRequestURL, setHeader, setResponseStatus } from 'h3' | ||
| import { withBase } from 'ufo' | ||
|
|
||
| export default defineEventHandler(async (event) => { | ||
| const mode = String(getQuery(event).mode) | ||
|
|
||
| const url = getRequestURL(event) | ||
|
|
||
| setResponseStatus(event, 302) | ||
| setHeader(event, 'location', { | ||
| relative: 'todos', | ||
| absolute: '/api/todos', | ||
| protocol: 'https://jsonplaceholder.typicode.com/todos', | ||
| outside: '/', | ||
| external: withBase('/api/todos', String(url.origin)), | ||
| }[mode] || '/api/todos') | ||
| }) |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Turns out addTemplate forces
write = truewhen the filename ends in.d.tslol