-
Notifications
You must be signed in to change notification settings - Fork 5.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1453 from cdr/proxy
HTTP proxy
- Loading branch information
Showing
14 changed files
with
373 additions
and
47 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
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
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
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
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 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
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
Oops, something went wrong.