Skip to content

fix: added support for setting port #132

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 3 commits into from
Feb 4, 2025
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 2 additions & 2 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@contentstack/delivery-sdk",
"version": "4.5.0",
"version": "4.5.1",
"type": "module",
"license": "MIT",
"main": "./dist/legacy/index.cjs",
Expand Down
3 changes: 2 additions & 1 deletion src/lib/contentstack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ export function stack(config: StackConfig): StackClass {
defaultHostname: 'cdn.contentstack.io',
headers: {} as AxiosRequestHeaders,
params: {} as any,
live_preview: {} as any
live_preview: {} as any,
port: config.port as number,
};

defaultConfig.defaultHostname = config.host || Utility.getHost(config.region, config.host);
Expand Down
50 changes: 32 additions & 18 deletions src/lib/stack.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { StackConfig, SyncStack, SyncType, LivePreviewQuery } from './types';
import { AxiosInstance } from '@contentstack/core';
import { Asset } from './asset';
import { AssetQuery } from './asset-query';
import { ContentType } from './content-type';
import { ContentTypeQuery } from './contenttype-query';
import { synchronization } from './synchronization';
import {TaxonomyQuery} from './taxonomy-query';
import { GlobalFieldQuery } from './global-field-query';
import { GlobalField } from './global-field';
import { StackConfig, SyncStack, SyncType, LivePreviewQuery } from "./types";
import { AxiosInstance } from "@contentstack/core";
import { Asset } from "./asset";
import { AssetQuery } from "./asset-query";
import { ContentType } from "./content-type";
import { ContentTypeQuery } from "./contenttype-query";
import { synchronization } from "./synchronization";
import { TaxonomyQuery } from "./taxonomy-query";
import { GlobalFieldQuery } from "./global-field-query";
import { GlobalField } from "./global-field";

export class Stack {
readonly config: StackConfig;
Expand Down Expand Up @@ -78,8 +78,8 @@ export class Stack {
* const taxonomy = stack.taxonomy() // For taxonomy query object
*/
taxonomy(): TaxonomyQuery {
return new TaxonomyQuery(this._client)
};
return new TaxonomyQuery(this._client);
}

/**
* @method GlobalField
Expand Down Expand Up @@ -170,20 +170,34 @@ export class Stack {
this._client.stackConfig.live_preview = livePreviewParams;
}

if (query.hasOwnProperty('release_id')) {
this._client.defaults.headers['release_id'] = query.release_id;
if (query.hasOwnProperty("release_id")) {
this._client.defaults.headers["release_id"] = query.release_id;
} else {
delete this._client.defaults.headers['release_id'];
delete this._client.defaults.headers["release_id"];
}

if (query.hasOwnProperty('preview_timestamp')) {
this._client.defaults.headers['preview_timestamp'] = query.preview_timestamp;
if (query.hasOwnProperty("preview_timestamp")) {
this._client.defaults.headers["preview_timestamp"] =
query.preview_timestamp;
} else {
delete this._client.defaults.headers['preview_timestamp'];
delete this._client.defaults.headers["preview_timestamp"];
}
}

getClient(): any {
return this._client;
}

/**
* @method setPort
* @memberOf Stack
* @description Sets the port of the host
* @param {Number} port - Port Number
* @return {Stack}
* @instance
* */
setPort(port: number) {
if (typeof port === "number") this.config.port = port;
return this;
}
}
1 change: 1 addition & 0 deletions src/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export interface StackConfig extends HttpClientParams {
logHandler?: (level: string, data: any) => void;
cacheOptions?: CacheOptions;
live_preview?: LivePreview;
port?: number;
}
export interface CacheOptions extends PersistanceStoreOptions {
policy: Policy;
Expand Down
5 changes: 5 additions & 0 deletions test/unit/stack.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,5 +144,10 @@ describe('Stack class tests', () => {

expect(stack.getClient().defaults.headers['preview_timestamp']).toBeUndefined();
});

it('should set port to 3000', () => {
stack.setPort(3000);
expect(stack.config.port).toEqual(3000);
});
});