Skip to content

Commit 5575481

Browse files
authored
Ngrok Startup Options (#2111)
* Make sure ngrok running loop not hit everytime
1 parent 6a43fda commit 5575481

File tree

3 files changed

+99
-19
lines changed

3 files changed

+99
-19
lines changed

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7-
## v4.8.1 - 2019 - 03 - 16
7+
## v4.8.1 - 2019 - 03 - 18
88
## Fixed
99
- [build] Replaced a missing .icns file that was deleted by mistake in a previous PR. Fixes the app icon on Linux & Mac in PR [2104](https://github.com/microsoft/BotFramework-Emulator/pull/2104)
1010
- [client] Fixed an issue where Restart activity wont appear on selected activity after restarting once in PR [2105](https://github.com/microsoft/BotFramework-Emulator/pull/2105)
1111
- [client] Disable "Restart conversation from here" bubble on DL Speech bots [2107](https://github.com/microsoft/BotFramework-Emulator/pull/2107)
1212
- [client] Fixed an issue where starting a conversation with an unset custom user ID was causing the User member of the conversation to have a blank `id` field in PR [2108](https://github.com/microsoft/BotFramework-Emulator/pull/2108)
13+
- [main] Fixed an issue where the setting `Bypass Ngrok for local addresses` was continuing to use the ngrok tunnel even for local bots in PR [2111](https://github.com/microsoft/BotFramework-Emulator/pull/2111)
14+
1315

1416
## v4.8.0 - 2019 - 03 - 12
1517
## Added

packages/app/main/src/ngrokService.spec.ts

Lines changed: 92 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -44,24 +44,26 @@ import { combineReducers, createStore } from 'redux';
4444
import { NgrokService } from './ngrokService';
4545
import { store } from './state/store';
4646

47-
const mockEmulator = {
48-
server: {
49-
serverUrl: 'http://localhost:3000',
50-
serverPort: 8080,
51-
state: {
52-
conversations: {
53-
getConversationIds: () => ['12', '123'],
54-
},
55-
endpoints: {
56-
reset: () => null,
57-
push: () => null,
47+
const mockEmulator = jest.fn(() => {
48+
return {
49+
server: {
50+
serverUrl: 'http://localhost:3000',
51+
serverPort: 8080,
52+
state: {
53+
conversations: {
54+
getConversationIds: () => ['12', '123'],
55+
},
56+
endpoints: {
57+
reset: () => null,
58+
push: () => null,
59+
},
5860
},
5961
},
60-
},
61-
};
62+
};
63+
});
6264
jest.mock('./emulator', () => ({
6365
Emulator: {
64-
getInstance: () => mockEmulator,
66+
getInstance: () => mockEmulator(),
6567
},
6668
}));
6769

@@ -209,4 +211,80 @@ describe('The ngrokService', () => {
209211

210212
(ngrokService as any).oauthNgrokInstance = undefined;
211213
});
214+
215+
describe('Conditions where service url returned is an ngrok url', () => {
216+
it('should always return ngrok url if runNgrokAtStartup is selected', async () => {
217+
const settings = {
218+
locale: 'en-us',
219+
bypassNgrokLocalhost: true,
220+
runNgrokAtStartup: true,
221+
ngrokPath: '/usr/bin/ngrok',
222+
};
223+
store.dispatch(setFrameworkSettings(settings as any));
224+
const serviceUrl = await ngrokService.getServiceUrl('http://my-azure.com/speech-bot/');
225+
expect(serviceUrl).toBe('http://fdsfds.ngrok.io');
226+
});
227+
228+
it('should always return ngrok url if remote bot irrespective of options selected', async () => {
229+
const settings = {
230+
locale: 'en-us',
231+
bypassNgrokLocalhost: false,
232+
runNgrokAtStartup: false,
233+
ngrokPath: '/usr/bin/ngrok',
234+
};
235+
store.dispatch(setFrameworkSettings(settings as any));
236+
const serviceUrl = await ngrokService.getServiceUrl('http://my-azure/api/messages');
237+
expect(serviceUrl).toBe('http://fdsfds.ngrok.io');
238+
});
239+
240+
it('should always return ngrok url if bypassNgrokLocalhost is not selected and ngrok is configured', async () => {
241+
const settings = {
242+
locale: 'en-us',
243+
bypassNgrokLocalhost: false,
244+
runNgrokAtStartup: false,
245+
ngrokPath: '/usr/bin/ngrok',
246+
};
247+
store.dispatch(setFrameworkSettings(settings as any));
248+
const serviceUrl = await ngrokService.getServiceUrl('http://localhost:3978');
249+
expect(serviceUrl).toBe('http://fdsfds.ngrok.io');
250+
});
251+
});
252+
253+
describe('Conditions where service url returned is a localhost url', () => {
254+
it('should always return localhost url if local bot and bypassNgrokLocalhost is selected', async () => {
255+
const settings = {
256+
locale: 'en-us',
257+
bypassNgrokLocalhost: true,
258+
runNgrokAtStartup: false,
259+
ngrokPath: '/usr/bin/ngrok',
260+
};
261+
store.dispatch(setFrameworkSettings(settings as any));
262+
const serviceUrl = await ngrokService.getServiceUrl('http://localhost:3978');
263+
expect(serviceUrl).toBe('http://localhost:8080');
264+
});
265+
266+
it('should always return localhost url if bypassNgrokLocalhost is not selected and ngrok is not configured and its a local bot', async () => {
267+
const settings = {
268+
locale: 'en-us',
269+
bypassNgrokLocalhost: false,
270+
runNgrokAtStartup: false,
271+
ngrokPath: '',
272+
};
273+
store.dispatch(setFrameworkSettings(settings as any));
274+
const serviceUrl = await ngrokService.getServiceUrl('http://localhost:3978');
275+
expect(serviceUrl).toBe('http://localhost:8080');
276+
});
277+
278+
it('should always return localhost url if ngrok is not configured', async () => {
279+
const settings = {
280+
locale: 'en-us',
281+
bypassNgrokLocalhost: false,
282+
runNgrokAtStartup: false,
283+
ngrokPath: '',
284+
};
285+
store.dispatch(setFrameworkSettings(settings as any));
286+
const serviceUrl = await ngrokService.getServiceUrl('http://my-azure/api/messages');
287+
expect(serviceUrl).toBe('http://localhost:8080');
288+
});
289+
});
212290
});

packages/app/main/src/ngrokService.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,13 @@ export class NgrokService {
7474
if (this.pendingRecycle) {
7575
await this.pendingRecycle;
7676
}
77-
if (this.ngrok.running()) {
78-
return this.serviceUrl;
79-
}
77+
8078
const { bypassNgrokLocalhost, runNgrokAtStartup } = getSettings().framework;
8179
// Use ngrok
8280
const local = !botUrl || isLocalHostUrl(botUrl);
83-
if (runNgrokAtStartup || !local || (local && !bypassNgrokLocalhost)) {
81+
82+
const useNgrok = runNgrokAtStartup || !local || (local && !bypassNgrokLocalhost);
83+
if (useNgrok) {
8484
if (!this.ngrok.running()) {
8585
await this.startup();
8686
}

0 commit comments

Comments
 (0)