Skip to content

Commit

Permalink
Allow URL for the baseUrl parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
cedx committed Feb 1, 2024
1 parent e79d23d commit 40baa89
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,11 @@ export class Client {
* @param options An object providing values to initialize this instance.
*/
constructor(apiKey: string, blog: Blog, options: Partial<ClientOptions> = {}) {
const baseUrl = options.baseUrl ?? "https://rest.akismet.com";
const {baseUrl = "https://rest.akismet.com"} = options;
const url = baseUrl instanceof URL ? baseUrl.href : baseUrl;

this.apiKey = apiKey;
this.baseUrl = new URL(baseUrl.endsWith("/") ? baseUrl : `${baseUrl}/`);
this.baseUrl = new URL(url.endsWith("/") ? url : `${url}/`);
this.blog = blog;
this.isTest = options.isTest ?? false;
this.userAgent = options.userAgent ?? `Node.js/${version.slice(1)} | Akismet/${Client.#version}`;
Expand Down Expand Up @@ -140,7 +142,7 @@ export interface ClientOptions {
/**
* The base URL of the remote API endpoint.
*/
baseUrl: string;
baseUrl: URL|string;

/**
* Value indicating whether the client operates in test mode.
Expand Down

0 comments on commit 40baa89

Please sign in to comment.