Skip to content
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

App Hosting Emulator: Auto-Init Support - Inject hostnames of other emulators into the app hosting emulator #8064

Merged
merged 5 commits into from
Jan 6, 2025
Merged
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
11 changes: 11 additions & 0 deletions src/emulator/apphosting/serve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
import { Emulators } from "../types";
import { getLocalAppHostingConfiguration } from "./config";
import { resolveProjectPath } from "../../projectPath";
import { EmulatorRegistry } from "../registry";
import { setEnvVarsForEmulators } from "../env";

interface StartOptions {
port?: number;
Expand All @@ -34,7 +36,7 @@
port += 1;
}

serve(port, options?.startCommand, options?.rootDirectory);

Check warning on line 39 in src/emulator/apphosting/serve.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Promises must be awaited, end with a call to .catch, end with a call to .then with a rejection handler or be explicitly marked as ignored with the `void` operator

return { hostname, port };
}
Expand All @@ -51,10 +53,11 @@
const environmentVariablesAsRecord: Record<string, string> = {};

for (const env of apphostingLocalConfig.environmentVariables) {
environmentVariablesAsRecord[env.variable] = env.value!;

Check warning on line 56 in src/emulator/apphosting/serve.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Forbidden non-null assertion
}

const environmentVariablesToInject = {
...getEmulatorEnvs(),
...environmentVariablesAsRecord,
PORT: port.toString(),
};
Expand All @@ -81,3 +84,11 @@
family: isIPv4(host) ? "IPv4" : "IPv6",
});
}

function getEmulatorEnvs(): Record<string, string> {
const envs: Record<string, string> = {};
const emulatorInfos = EmulatorRegistry.listRunningWithInfo();
setEnvVarsForEmulators(envs, emulatorInfos);

return envs;
}
Loading