allows binding to loopback interface via app config instead of only docker

This commit is contained in:
nai-degen 2024-01-15 11:32:26 -06:00
parent 85d89bdb9f
commit ad6e5224e3
3 changed files with 15 additions and 8 deletions

View File

@ -57,8 +57,9 @@
# Requires additional setup. See `docs/google-sheets.md` for more information.
# PROMPT_LOGGING=false
# The port to listen on.
# The port and network interface to listen on.
# PORT=7860
# BIND_ADDRESS=0.0.0.0
# Whether cookies should be set without the Secure flag, for hosts that don't support SSL.
# USE_INSECURE_COOKIES=false

View File

@ -16,6 +16,8 @@ export const USER_ASSETS_DIR = path.join(DATA_DIR, "user-files");
type Config = {
/** The port the proxy server will listen on. */
port: number;
/** The network interface the proxy server will listen on. */
bindAddress: string;
/** Comma-delimited list of OpenAI API keys. */
openaiKey?: string;
/** Comma-delimited list of Anthropic API keys. */
@ -240,6 +242,7 @@ type Config = {
// See .env.example for an example.
export const config: Config = {
port: getEnvWithDefault("PORT", 7860),
bindAddress: getEnvWithDefault("BIND_ADDRESS", "0.0.0.0"),
openaiKey: getEnvWithDefault("OPENAI_KEY", ""),
anthropicKey: getEnvWithDefault("ANTHROPIC_KEY", ""),
googleAIKey: getEnvWithDefault("GOOGLE_AI_KEY", ""),

View File

@ -12,7 +12,7 @@ import { setupAssetsDir } from "./shared/file-storage/setup-assets-dir";
import { keyPool } from "./shared/key-management";
import { adminRouter } from "./admin/routes";
import { proxyRouter } from "./proxy/routes";
import { handleInfoPage, renderPage } from "./info-page";
import { handleInfoPage } from "./info-page";
import { buildInfo } from "./service-info";
import { logQueue } from "./shared/prompt-logging";
import { start as startRequestQueue } from "./proxy/queue";
@ -22,6 +22,7 @@ import { checkOrigin } from "./proxy/check-origin";
import { userRouter } from "./user/routes";
const PORT = config.port;
const BIND_ADDRESS = config.bindAddress;
const app = express();
// middleware
@ -123,15 +124,18 @@ async function start() {
logger.info("Starting request queue...");
startRequestQueue();
app.listen(PORT, async () => {
logger.info({ port: PORT }, "Now listening for connections.");
registerUncaughtExceptionHandler();
});
const diskSpace = await checkDiskSpace(
__dirname.startsWith("/app") ? "/app" : os.homedir()
);
app.listen(PORT, BIND_ADDRESS, () => {
logger.info(
{ port: PORT, interface: BIND_ADDRESS },
"Now listening for connections."
);
registerUncaughtExceptionHandler();
});
logger.info(
{ build: process.env.BUILD_INFO, nodeEnv: process.env.NODE_ENV, diskSpace },
"Startup complete."
@ -183,7 +187,6 @@ async function setBuildInfo() {
return;
}
// For huggingface and bare metal deployments, we can get the info from git
try {
if (process.env.SPACE_ID) {