Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 1 addition & 53 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 1 addition & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@
"js-sha512": "^0.8.0",
"json-bigint": "^1.0.0",
"superagent": "^6.1.0",
"tweetnacl": "^1.0.3",
"url-parse": "^1.5.1"
"tweetnacl": "^1.0.3"
},
"devDependencies": {
"@types/json-bigint": "^1.0.0",
Expand All @@ -53,7 +52,6 @@
"mocha": "^9.0.0",
"mocha-lcov-reporter": "^1.3.0",
"mock-http-server": "^1.4.3",
"path-browserify": "^1.0.1",
"prettier": "2.2.1",
"selenium-webdriver": "^4.2.0",
"source-map-loader": "^2.0.2",
Expand Down
27 changes: 18 additions & 9 deletions src/client/urlTokenBaseHTTPClient.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import Url from 'url-parse';
import path from 'path';
import * as request from 'superagent';
import {
BaseHTTPClient,
Expand Down Expand Up @@ -35,7 +33,7 @@ export type TokenHeader =
* This is the default implementation of BaseHTTPClient.
*/
export class URLTokenBaseHTTPClient implements BaseHTTPClient {
private readonly baseURL: Url;
private readonly baseURL: URL;
private readonly tokenHeader: TokenHeader;

constructor(
Expand All @@ -44,9 +42,15 @@ export class URLTokenBaseHTTPClient implements BaseHTTPClient {
port?: string | number,
private defaultHeaders: Record<string, any> = {}
) {
const baseServerURL = new Url(baseServer, {});
// Append a trailing slash so we can use relative paths. Without the trailing
// slash, the last path segment will be replaced by the relative path. See
// usage in `addressWithPath`.
const fixedBaseServer = baseServer.endsWith('/')
? baseServer
: `${baseServer}/`;
const baseServerURL = new URL(fixedBaseServer);
if (typeof port !== 'undefined') {
baseServerURL.set('port', port.toString());
baseServerURL.port = port.toString();
}

if (baseServerURL.protocol.length === 0) {
Expand All @@ -63,10 +67,15 @@ export class URLTokenBaseHTTPClient implements BaseHTTPClient {
* @returns A URL string
*/
private addressWithPath(relativePath: string) {
const address = new Url(
path.posix.join(this.baseURL.pathname, relativePath),
this.baseURL
);
let fixedRelativePath: string;
if (relativePath.startsWith('./')) {
fixedRelativePath = relativePath;
} else if (relativePath.startsWith('/')) {
fixedRelativePath = `.${relativePath}`;
} else {
fixedRelativePath = `./${relativePath}`;
}
const address = new URL(fixedRelativePath, this.baseURL);
return address.toString();
}

Expand Down
5 changes: 0 additions & 5 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,6 @@ module.exports = {
resolve: {
// Add '.ts' as resolvable extensions
extensions: ['.ts', '.js'],

// Support `path` in the browser
fallback: {
path: require.resolve('path-browserify'),
},
},
plugins: [
new webpack.ProvidePlugin({
Expand Down