ClickHouse / clickhouse-js

Official JS client for ClickHouse DB
https://clickhouse.com
Apache License 2.0
189 stars 22 forks source link

createClient doesn't work with URL on port 80 or 443 since 1.0.0 #258

Closed martoche closed 3 months ago

martoche commented 3 months ago

Describe the bug

Can't connect to a Clickhouse server that listens on port 443 (or when a reverse proxy on port 443 is used to forward requests to the Clickhouse server on any other port).

The following code :

const clickhouseClient = createClient({
  url: "https://localhost:443",
  pathname: "clickhouse",
  database: "apm",
})

Throws the error: Uncaught Error: ClickHouse URL must contain a valid port number.

This is because of these lines: https://github.com/ClickHouse/clickhouse-js/blob/64b5f8128cef4a868509aec3ce3879c7c9ca841a/packages/client-common/src/config.ts#L286-L288

The condition in the if is incorrect: when the URL scheme is "http" and the port is explicitely set as "80", then new URL("http://localhost:80").port is equal to the empty string. Similarily, new URL("https://localhost:443").port === "".

This is a regression of version 1.0.0, it works in 0.3.1.

Configuration

Environment

slvrtrn commented 3 months ago

On it, thanks for the report.

slvrtrn commented 3 months ago

@martoche, it should be fixed in 1.0.1. Thanks again for the report!