Use dynamic import for http module in OAuth files

Prevents browser bundles from failing on import.
The http module is only loaded when login functions are actually called.
This commit is contained in:
Mario Zechner 2025-12-28 11:17:08 +01:00
parent 481bc79f83
commit 3bf168615a
2 changed files with 14 additions and 4 deletions

View file

@ -6,7 +6,7 @@
* It is only intended for CLI use, not browser environments.
*/
import { createServer, type Server } from "http";
import type { Server } from "http";
import { generatePKCE } from "./pkce.js";
import type { OAuthCredentials } from "./types.js";
@ -36,7 +36,12 @@ const DEFAULT_PROJECT_ID = "rising-fact-p41fc";
/**
* Start a local HTTP server to receive the OAuth callback
*/
function startCallbackServer(): Promise<{ server: Server; getCode: () => Promise<{ code: string; state: string }> }> {
async function startCallbackServer(): Promise<{
server: Server;
getCode: () => Promise<{ code: string; state: string }>;
}> {
const { createServer } = await import("http");
return new Promise((resolve, reject) => {
let codeResolve: (value: { code: string; state: string }) => void;
let codeReject: (error: Error) => void;

View file

@ -6,7 +6,7 @@
* It is only intended for CLI use, not browser environments.
*/
import { createServer, type Server } from "http";
import type { Server } from "http";
import { generatePKCE } from "./pkce.js";
import type { OAuthCredentials } from "./types.js";
@ -28,7 +28,12 @@ const CODE_ASSIST_ENDPOINT = "https://cloudcode-pa.googleapis.com";
/**
* Start a local HTTP server to receive the OAuth callback
*/
function startCallbackServer(): Promise<{ server: Server; getCode: () => Promise<{ code: string; state: string }> }> {
async function startCallbackServer(): Promise<{
server: Server;
getCode: () => Promise<{ code: string; state: string }>;
}> {
const { createServer } = await import("http");
return new Promise((resolve, reject) => {
let codeResolve: (value: { code: string; state: string }) => void;
let codeReject: (error: Error) => void;