allows binding to loopback interface via app config instead of only docker
This commit is contained in:
+2
-1
@@ -57,8 +57,9 @@
|
|||||||
# Requires additional setup. See `docs/google-sheets.md` for more information.
|
# Requires additional setup. See `docs/google-sheets.md` for more information.
|
||||||
# PROMPT_LOGGING=false
|
# PROMPT_LOGGING=false
|
||||||
|
|
||||||
# The port to listen on.
|
# The port and network interface to listen on.
|
||||||
# PORT=7860
|
# PORT=7860
|
||||||
|
# BIND_ADDRESS=0.0.0.0
|
||||||
|
|
||||||
# Whether cookies should be set without the Secure flag, for hosts that don't support SSL.
|
# Whether cookies should be set without the Secure flag, for hosts that don't support SSL.
|
||||||
# USE_INSECURE_COOKIES=false
|
# USE_INSECURE_COOKIES=false
|
||||||
|
|||||||
@@ -16,6 +16,8 @@ export const USER_ASSETS_DIR = path.join(DATA_DIR, "user-files");
|
|||||||
type Config = {
|
type Config = {
|
||||||
/** The port the proxy server will listen on. */
|
/** The port the proxy server will listen on. */
|
||||||
port: number;
|
port: number;
|
||||||
|
/** The network interface the proxy server will listen on. */
|
||||||
|
bindAddress: string;
|
||||||
/** Comma-delimited list of OpenAI API keys. */
|
/** Comma-delimited list of OpenAI API keys. */
|
||||||
openaiKey?: string;
|
openaiKey?: string;
|
||||||
/** Comma-delimited list of Anthropic API keys. */
|
/** Comma-delimited list of Anthropic API keys. */
|
||||||
@@ -240,6 +242,7 @@ type Config = {
|
|||||||
// See .env.example for an example.
|
// See .env.example for an example.
|
||||||
export const config: Config = {
|
export const config: Config = {
|
||||||
port: getEnvWithDefault("PORT", 7860),
|
port: getEnvWithDefault("PORT", 7860),
|
||||||
|
bindAddress: getEnvWithDefault("BIND_ADDRESS", "0.0.0.0"),
|
||||||
openaiKey: getEnvWithDefault("OPENAI_KEY", ""),
|
openaiKey: getEnvWithDefault("OPENAI_KEY", ""),
|
||||||
anthropicKey: getEnvWithDefault("ANTHROPIC_KEY", ""),
|
anthropicKey: getEnvWithDefault("ANTHROPIC_KEY", ""),
|
||||||
googleAIKey: getEnvWithDefault("GOOGLE_AI_KEY", ""),
|
googleAIKey: getEnvWithDefault("GOOGLE_AI_KEY", ""),
|
||||||
|
|||||||
+10
-7
@@ -12,7 +12,7 @@ import { setupAssetsDir } from "./shared/file-storage/setup-assets-dir";
|
|||||||
import { keyPool } from "./shared/key-management";
|
import { keyPool } from "./shared/key-management";
|
||||||
import { adminRouter } from "./admin/routes";
|
import { adminRouter } from "./admin/routes";
|
||||||
import { proxyRouter } from "./proxy/routes";
|
import { proxyRouter } from "./proxy/routes";
|
||||||
import { handleInfoPage, renderPage } from "./info-page";
|
import { handleInfoPage } from "./info-page";
|
||||||
import { buildInfo } from "./service-info";
|
import { buildInfo } from "./service-info";
|
||||||
import { logQueue } from "./shared/prompt-logging";
|
import { logQueue } from "./shared/prompt-logging";
|
||||||
import { start as startRequestQueue } from "./proxy/queue";
|
import { start as startRequestQueue } from "./proxy/queue";
|
||||||
@@ -22,6 +22,7 @@ import { checkOrigin } from "./proxy/check-origin";
|
|||||||
import { userRouter } from "./user/routes";
|
import { userRouter } from "./user/routes";
|
||||||
|
|
||||||
const PORT = config.port;
|
const PORT = config.port;
|
||||||
|
const BIND_ADDRESS = config.bindAddress;
|
||||||
|
|
||||||
const app = express();
|
const app = express();
|
||||||
// middleware
|
// middleware
|
||||||
@@ -123,15 +124,18 @@ async function start() {
|
|||||||
logger.info("Starting request queue...");
|
logger.info("Starting request queue...");
|
||||||
startRequestQueue();
|
startRequestQueue();
|
||||||
|
|
||||||
app.listen(PORT, async () => {
|
|
||||||
logger.info({ port: PORT }, "Now listening for connections.");
|
|
||||||
registerUncaughtExceptionHandler();
|
|
||||||
});
|
|
||||||
|
|
||||||
const diskSpace = await checkDiskSpace(
|
const diskSpace = await checkDiskSpace(
|
||||||
__dirname.startsWith("/app") ? "/app" : os.homedir()
|
__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(
|
logger.info(
|
||||||
{ build: process.env.BUILD_INFO, nodeEnv: process.env.NODE_ENV, diskSpace },
|
{ build: process.env.BUILD_INFO, nodeEnv: process.env.NODE_ENV, diskSpace },
|
||||||
"Startup complete."
|
"Startup complete."
|
||||||
@@ -183,7 +187,6 @@ async function setBuildInfo() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// For huggingface and bare metal deployments, we can get the info from git
|
// For huggingface and bare metal deployments, we can get the info from git
|
||||||
try {
|
try {
|
||||||
if (process.env.SPACE_ID) {
|
if (process.env.SPACE_ID) {
|
||||||
|
|||||||
Reference in New Issue
Block a user