Skip to content

Commit

Permalink
Merge 1b77263 into c327794
Browse files Browse the repository at this point in the history
  • Loading branch information
samtstern committed Jun 14, 2019
2 parents c327794 + 1b77263 commit 6a352c4
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 8 deletions.
1 change: 1 addition & 0 deletions changelog.txt
@@ -0,0 +1 @@
* Fixes bug where `firebase serve --only functions` dropped the host argument.
19 changes: 13 additions & 6 deletions src/emulator/functionsEmulator.ts
Expand Up @@ -65,8 +65,14 @@ interface RequestWithRawBody extends express.Request {
}

export class FunctionsEmulator implements EmulatorInstance {
static getHttpFunctionUrl(port: number, projectId: string, name: string, region: string): string {
return `http://localhost:${port}/${projectId}/${region}/${name}`;
static getHttpFunctionUrl(
host: string,
port: number,
projectId: string,
name: string,
region: string
): string {
return `http://${host}:${port}/${projectId}/${region}/${name}`;
}

static createHubServer(
Expand Down Expand Up @@ -401,15 +407,13 @@ You can probably fix this by running "npm install ${
readonly bundleTemplate: FunctionsRuntimeBundle;
nodeBinary: string = "";

private readonly port: number;
private server?: http.Server;
private firebaseConfig: any;
private functionsDir: string = "";
private triggers: EmulatedTriggerDefinition[] = [];
private knownTriggerIDs: { [triggerId: string]: boolean } = {};

constructor(private options: any, private args: FunctionsEmulatorArgs) {
this.port = this.args.port || Constants.getDefaultPort(Emulators.FUNCTIONS);
this.projectId = getProjectId(this.options, false);

this.functionsDir = path.join(
Expand All @@ -435,8 +439,10 @@ You can probably fix this by running "npm install ${
// TODO: This call requires authentication, which we should remove eventually
this.firebaseConfig = await functionsConfig.getFirebaseConfig(this.options);

const { host, port } = this.getInfo();
this.server = FunctionsEmulator.createHubServer(this.bundleTemplate, this.nodeBinary).listen(
this.port
port,
host
);
}

Expand Down Expand Up @@ -489,7 +495,8 @@ You can probably fix this by running "npm install ${
// that a developer is running the same function in multiple regions.
const region = getFunctionRegion(definition);
const url = FunctionsEmulator.getHttpFunctionUrl(
this.port,
this.getInfo().host,
this.getInfo().port,
this.projectId,
definition.name,
region
Expand Down
1 change: 1 addition & 0 deletions src/emulator/functionsEmulatorShell.ts
Expand Up @@ -29,6 +29,7 @@ export class FunctionsEmulatorShell implements FunctionsShellController {

if (trigger.httpsTrigger) {
this.urls[name] = FunctionsEmulator.getHttpFunctionUrl(
this.emu.getInfo().host,
this.emu.getInfo().port,
this.emu.projectId,
name,
Expand Down
4 changes: 2 additions & 2 deletions src/hosting/functionsProxy.ts
Expand Up @@ -39,9 +39,9 @@ export default function(
// things still point to production.
const functionsEmu = EmulatorRegistry.get(Emulators.FUNCTIONS);
if (functionsEmu) {
const port = functionsEmu.getInfo().port;
url = FunctionsEmulator.getHttpFunctionUrl(
port,
functionsEmu.getInfo().host,
functionsEmu.getInfo().port,
projectId,
rewrite.function,
"us-central1"
Expand Down
4 changes: 4 additions & 0 deletions src/serve/functions.ts
Expand Up @@ -23,6 +23,10 @@ module.exports = {
};
}

if (options.host) {
args.host = options.host;
}

// If hosting emulator is not being served but Functions is,
// we can use the port argument. Otherwise it goes to hosting and
// we use port + 1.
Expand Down

0 comments on commit 6a352c4

Please sign in to comment.