Skip to content

Commit c1e47cb

Browse files
Merge pull request #5011 from NativeScript/release-patch
chore: merge release-patch in release
2 parents 7ecd4d6 + 7708ea4 commit c1e47cb

File tree

4 files changed

+25
-2
lines changed

4 files changed

+25
-2
lines changed

lib/services/ip-service.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1+
import { cache } from "../common/decorators";
2+
13
export class IPService implements IIPService {
24
private static GET_IP_TIMEOUT = 1000;
35
constructor(private $config: IConfiguration,
46
private $httpClient: Server.IHttpClient,
57
private $logger: ILogger) { }
68

9+
@cache()
710
public async getCurrentIPv4Address(): Promise<string> {
811
const ipAddress = await this.getIPAddressFromServiceReturningJSONWithIPProperty(this.$config.WHOAMI_URL_ENDPOINT) ||
912
await this.getIPAddressFromServiceReturningJSONWithIPProperty("https://api.myip.com") ||

npm-shrinkwrap.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "nativescript",
33
"preferGlobal": true,
4-
"version": "6.1.0",
4+
"version": "6.1.1",
55
"author": "Telerik <support@telerik.com>",
66
"description": "Command-line interface for building NativeScript projects",
77
"bin": {

test/services/ip-service.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,5 +135,25 @@ describe("ipService", () => {
135135
assert.isTrue(logger.traceOutput.indexOf(errMsgForMyipCom) !== -1, `Trace output\n'${logger.traceOutput}'\ndoes not contain expected message:\n${errMsgForMyipCom}`);
136136
assert.isTrue(logger.traceOutput.indexOf(errMsgForIpifyOrg) !== -1, `Trace output\n'${logger.traceOutput}'\ndoes not contain expected message:\n${errMsgForMyipCom}`);
137137
});
138+
139+
it("is called only once per process", async () => {
140+
const testInjector = createTestInjector();
141+
const httpClient = testInjector.resolve<Server.IHttpClient>("httpClient");
142+
let httpRequestCounter = 0;
143+
httpClient.httpRequest = async (options: any, proxySettings?: IProxySettings): Promise<Server.IResponse> => {
144+
httpRequestCounter++;
145+
return <any>{ body: JSON.stringify({ ip }) };
146+
};
147+
148+
const ipService = testInjector.resolve<IIPService>("ipService");
149+
150+
const ipAddress = await ipService.getCurrentIPv4Address();
151+
assert.equal(httpRequestCounter, 1);
152+
assert.equal(ipAddress, ip);
153+
154+
const ipAddress2 = await ipService.getCurrentIPv4Address();
155+
assert.equal(httpRequestCounter, 1);
156+
assert.equal(ipAddress2, ip);
157+
});
138158
});
139159
});

0 commit comments

Comments
 (0)