-
Notifications
You must be signed in to change notification settings - Fork 6k
pathProxy.ts: Implement --proxy-path-passthrough #2563
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
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
f169e3a
pathProxy.ts: Implement --proxy-path-passthrough
nhooyr 497b01b
FAQ.md: Document --proxy-path-passthrough
nhooyr ba4a248
routes/index.ts: Correctly register wsErrorHandler
nhooyr 9efcf7f
FAQ.md: Document wds problem with create-react-app and pathProxy.ts
nhooyr ea1949e
test: Add testutil.HttpServer
nhooyr 8acb2ae
plugin.test.ts: Switch to testutil.HttpServer
nhooyr d307427
app.ts: Fix createApp to log all http server errors
nhooyr 64e915d
test: Rename testutil.ts to httpserver.ts
nhooyr 240c8e2
test: Implement integration.ts for near full stack integration testing
nhooyr 60233d0
test/proxy.test.ts: Implement
nhooyr 5c06646
Formatting and linting fixes
nhooyr c32d8b1
heart.ts: Fix leak when server closes
nhooyr 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
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,72 @@ | ||
import * as http from "http" | ||
import * as nodeFetch from "node-fetch" | ||
import * as util from "../src/common/util" | ||
import { ensureAddress } from "../src/node/app" | ||
|
||
// Perhaps an abstraction similar to this should be used in app.ts as well. | ||
export class HttpServer { | ||
private hs = http.createServer() | ||
|
||
public constructor(hs?: http.Server) { | ||
// See usage in test/integration.ts | ||
if (hs) { | ||
this.hs = hs | ||
} | ||
} | ||
|
||
/** | ||
* listen starts the server on a random localhost port. | ||
* Use close to cleanup when done. | ||
*/ | ||
public listen(fn: http.RequestListener): Promise<void> { | ||
this.hs.on("request", fn) | ||
|
||
let resolved = false | ||
return new Promise((res, rej) => { | ||
this.hs.listen(0, "localhost", () => { | ||
res() | ||
resolved = true | ||
}) | ||
|
||
this.hs.on("error", (err) => { | ||
if (!resolved) { | ||
rej(err) | ||
} else { | ||
// Promise resolved earlier so this is some other error. | ||
util.logError("http server error", err) | ||
} | ||
}) | ||
}) | ||
} | ||
|
||
/** | ||
* close cleans up the server. | ||
*/ | ||
public close(): Promise<void> { | ||
return new Promise((res, rej) => { | ||
this.hs.close((err) => { | ||
if (err) { | ||
rej(err) | ||
return | ||
} | ||
res() | ||
}) | ||
}) | ||
} | ||
|
||
/** | ||
* fetch fetches the request path. | ||
* The request path must be rooted! | ||
*/ | ||
public fetch(requestPath: string, opts?: nodeFetch.RequestInit): Promise<nodeFetch.Response> { | ||
return nodeFetch.default(`${ensureAddress(this.hs)}${requestPath}`, opts) | ||
} | ||
|
||
public port(): number { | ||
const addr = this.hs.address() | ||
if (addr && typeof addr === "object") { | ||
return addr.port | ||
} | ||
throw new Error("server not listening or listening on unix socket") | ||
} | ||
} |
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,21 @@ | ||
import * as express from "express" | ||
import { createApp } from "../src/node/app" | ||
import { parse, setDefaults, parseConfigFile, DefaultedArgs } from "../src/node/cli" | ||
import { register } from "../src/node/routes" | ||
import * as httpserver from "./httpserver" | ||
|
||
export async function setup( | ||
argv: string[], | ||
configFile?: string, | ||
): Promise<[express.Application, express.Application, httpserver.HttpServer, DefaultedArgs]> { | ||
argv = ["--bind-addr=localhost:0", ...argv] | ||
|
||
const cliArgs = parse(argv) | ||
const configArgs = parseConfigFile(configFile || "", "test/integration.ts") | ||
const args = await setDefaults(cliArgs, configArgs) | ||
|
||
const [app, wsApp, server] = await createApp(args) | ||
await register(app, wsApp, server, args) | ||
|
||
return [app, wsApp, new httpserver.HttpServer(server), args] | ||
} |
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.