-
Notifications
You must be signed in to change notification settings - Fork 5.9k
HTTP proxy #1453
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
Merged
Merged
HTTP proxy #1453
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
37299ab
Minor startup code improvements
code-asher 13534fa
Add proxy-domain flag
code-asher 77ad73d
Set domain on cookie
code-asher 90fd1f7
Add proxy provider
code-asher 3a98d85
Handle authentication with proxy
code-asher 2086648
Only handle exact domain matches
code-asher 8aa5675
Implement the actual proxy
code-asher c0dd29c
Fix domains with ports & localhost subdomains
code-asher 737a8f5
Catch proxy errors
code-asher e68d72c
Add documentation for proxying
code-asher 561b634
Ensure a trailing slash on subpath proxy
code-asher fd339a7
Include query parameters when proxying
code-asher e7e7b0f
Fix redirects through subpath proxy
code-asher 74a0bac
Rename hxxp to isHttp
code-asher 411c61f
Create helper for determining if route is the root
code-asher 498becd
Use route.fullPath when adding trailing slash
code-asher aaa6c27
Use Set for proxy domains
code-asher a5d1d3b
Move proxy logic into main HTTP server
code-asher 363cdd0
Improve proxy documentation
code-asher a288351
Respond when proxy errors
code-asher 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
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
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,43 @@ | ||
import * as http from "http" | ||
import { HttpCode, HttpError } from "../../common/http" | ||
import { HttpProvider, HttpResponse, Route, WsResponse } from "../http" | ||
|
||
/** | ||
* Proxy HTTP provider. | ||
*/ | ||
export class ProxyHttpProvider extends HttpProvider { | ||
public async handleRequest(route: Route, request: http.IncomingMessage): Promise<HttpResponse> { | ||
if (!this.authenticated(request)) { | ||
if (this.isRoot(route)) { | ||
return { redirect: "/login", query: { to: route.fullPath } } | ||
} | ||
throw new HttpError("Unauthorized", HttpCode.Unauthorized) | ||
} | ||
|
||
// Ensure there is a trailing slash so relative paths work correctly. | ||
if (this.isRoot(route) && !route.fullPath.endsWith("/")) { | ||
return { | ||
redirect: `${route.fullPath}/`, | ||
} | ||
} | ||
|
||
const port = route.base.replace(/^\//, "") | ||
return { | ||
proxy: { | ||
base: `${this.options.base}/${port}`, | ||
port, | ||
}, | ||
} | ||
} | ||
|
||
public async handleWebSocket(route: Route, request: http.IncomingMessage): Promise<WsResponse> { | ||
this.ensureAuthenticated(request) | ||
const port = route.base.replace(/^\//, "") | ||
return { | ||
proxy: { | ||
base: `${this.options.base}/${port}`, | ||
port, | ||
}, | ||
} | ||
} | ||
} |
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
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.
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.
Why do we have a SSH server?
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.
I believe this has something to do with the Chrome extension that was planned but I'm not 100% sure on the status of that. @kylecarbs @wbobeirne
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.
Yes, this was for the browser extension. That's pretty much on ice at this point, so I think it's probably best for safety / code cleanliness that we take it out since nothing is using it right now, and it's probably a liability to have such a powerful thing up by default. Or at the very least, disable by default.
Would be happy to make a PR to remove that if we're definitely not going to pursue the extension, but I'll defer to mr @kylecarbs on that.