Skip to content

enable typescript strict checks #9

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

Conversation

sapphi-red
Copy link
Contributor

Added strict: true to tsconfig.json and fixed the type errors so that it's easier to maintain.

@sapphi-red sapphi-red force-pushed the refacotr/enable-ts-strict-checks branch from 350a403 to 7d22922 Compare July 12, 2025 16:45
@@ -12,7 +12,6 @@ export const isSSL = /^https|wss/;
type Outgoing0 = ProxyTargetDetailed & ServerOptions;

export interface Outgoing extends Outgoing0 {
method?: any;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is moved to ServerOptions.

outgoing.port =
options[forward || "target"].port ??
(isSSL.test(options[forward || "target"].protocol) ? 443 : 80);
+(target.port ?? (target.protocol !== undefined && isSSL.test(target.protocol) ? 443 : 80));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+ is to convert options[forward || "target"].port (string | number) to number.

Comment on lines -90 to +92
if (isSSL.test(options[forward || "target"].protocol)) {
if (target.protocol !== undefined && isSSL.test(target.protocol)) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When target.protocol is undefined, it was working like isSSL.test('undefined') and returned false.

Comment on lines +127 to +128
target.protocol !== undefined &&
required(outgoing.port, target.protocol) &&
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When target.protocol is undefined, required(outgoing.port, options[forward || "target"].protocol) throwed an error before this PR.

Comment on lines +156 to 157
// @ts-expect-error FIXME: options.target may be undefined
const proto = common.isSSL.test(options.target.protocol) ? https : http;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is probably a bug. If options.forward is set and options.target is not set, this line throws an error. I kept the behavior for now.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed.

it("creates the round robin proxy server", async () => {
// create one proxy for each backend server
const proxies = addresses.map((target) =>
httpProxy.createProxyServer({ target }),
);

proxyPort = await getPort();
servers.proxy = httpProxy.createProxyServer({});
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line doesn't seem to be needed.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

feel free to remove it in another PR.

Comment on lines -28 to +29
port: "you",
port: 3000,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change is needed because of #9 (comment)

@@ -154,7 +155,7 @@ describe("#setupOutgoing", () => {

it("should set the agent to false if none is given", () => {
const outgoing: any = {};
setupOutgoing(outgoing, { target: "http://localhost" }, { url: "/" });
setupOutgoing(outgoing, { target: new URL("http://localhost") }, { url: "/" });
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

setupOutgoing expects target to be normalized.

@williamstein williamstein merged commit 0dd8799 into sagemathinc:main Jul 12, 2025
4 checks passed
@williamstein
Copy link
Contributor

Thanks!!! Merged and published.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants