Skip to content

Commit

Permalink
fix(core.gbapp): Self-replication on Azure
Browse files Browse the repository at this point in the history
  • Loading branch information
rodrigorodriguez committed May 27, 2019
1 parent bf602c6 commit e82a813
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
2 changes: 1 addition & 1 deletion packages/core.gbapp/services/GBDeployer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ export class GBDeployer {
botPackages.forEach(async (e) => {
if (e !== 'packages\\boot.gbot') {
GBLog.info(`Deploying bot: ${e}...`);
await _this.deployBot(e, GBServer.globals.proxyAddress);
await _this.deployBot(e, GBServer.globals.publicAddress);
GBLog.info(`Bot: ${e} deployed...`);
}
});
Expand Down
2 changes: 1 addition & 1 deletion packages/whatsapp.gblib/services/WhatsappDirectLine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export class WhatsappDirectLine extends GBService {
url: urlJoin(this.whatsappServiceUrl, 'webhook'),
qs: {
token: this.whatsappServiceKey,
webhookUrl: `${GBServer.globals.proxyAddress}/instances/${this.botId}/whatsapp`,
webhookUrl: `${GBServer.globals.publicAddress}/instances/${this.botId}/whatsapp`,
set: true
},
headers: {
Expand Down
20 changes: 13 additions & 7 deletions src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ const appPackages: IGBPackage[] = [];
* Global shared server data;
*/
export class RootData {
public proxyAddress: string;
public publicAddress: string;
}

/**
Expand Down Expand Up @@ -93,10 +93,16 @@ export class GBServer {
const adminService: GBAdminService = new GBAdminService(core);
const conversationalService: GBConversationalService = new GBConversationalService(core);

// Ensure that local development proxy is setup.
if (process.env.NODE_ENV === 'development') {
// Ensure that local development proxy is setup.

GBLog.info(`Establishing a development local proxy (ngrok)...`);
GBServer.globals.proxyAddress = await core.ensureProxy(port);
GBLog.info(`Establishing a development local proxy (ngrok)...`);
GBServer.globals.publicAddress = await core.ensureProxy(port);
} else {
const serverAddress = `http://${process.env.WEBSITE_SITE_NAME}.azurewebsites.net`;
GBLog.info(`Defining server address at ${serverAddress}...`);
GBServer.globals.publicAddress = serverAddress;
}

// Creates a boot instance or load it from storage.

Expand All @@ -105,7 +111,7 @@ export class GBServer {
await core.initStorage();
} catch (error) {
GBLog.verbose(`Error initializing storage: ${error}`);
bootInstance = await core.createBootInstance(core, azureDeployer, GBServer.globals.proxyAddress);
bootInstance = await core.createBootInstance(core, azureDeployer, GBServer.globals.publicAddress);
await core.initStorage();
}

Expand Down Expand Up @@ -133,7 +139,7 @@ export class GBServer {
const fullInstance = Object.assign(packageInstance, bootInstance);
await core.saveInstance(fullInstance);
let instances: IGBInstance[] = await core.loadAllInstances(core, azureDeployer,
GBServer.globals.proxyAddress);
GBServer.globals.publicAddress);
instances = await core.ensureInstances(instances, bootInstance, core);
if (bootInstance !== undefined) {
bootInstance = instances[0];
Expand All @@ -143,7 +149,7 @@ export class GBServer {

const minService: GBMinService = new GBMinService(core, conversationalService, adminService, deployer);
await minService.buildMin(bootInstance, server, appPackages, instances,
deployer, GBServer.globals.proxyAddress);
deployer, GBServer.globals.publicAddress);

// Deployment of local applications for the first time.

Expand Down

0 comments on commit e82a813

Please sign in to comment.