config: bind to localhost by default

Signed-off-by: NotAShelf <raf@notashelf.dev>
Change-Id: I00aca92a09291ce12f09da68917f56c06a6a6964
This commit is contained in:
raf 2026-02-01 17:16:58 +03:00
commit 7d8bc6943d
Signed by: NotAShelf
GPG key ID: 29D95B64378DB4BF
3 changed files with 50 additions and 5 deletions

View file

@ -97,7 +97,10 @@ export function loadConfig(): Config {
);
}
const config = deepMerge(defaults, fileConfig);
const config = deepMerge(
defaults as unknown as Record<string, unknown>,
fileConfig as unknown as Record<string, unknown>
) as unknown as Config;
// Environment variable overrides
if (process.env.PORT) {
@ -108,6 +111,31 @@ export function loadConfig(): Config {
config.server.port = parsed;
}
if (process.env.HOST) {
config.server.host = process.env.HOST;
}
if (process.env.DASHBOARD_TOKEN) {
config.dashboard = {
...(config.dashboard || { enabled: true }),
auth: {
type: 'token',
token: process.env.DASHBOARD_TOKEN,
},
};
}
if (process.env.DASHBOARD_USERNAME && process.env.DASHBOARD_PASSWORD) {
config.dashboard = {
...(config.dashboard || { enabled: true }),
auth: {
type: 'basic',
username: process.env.DASHBOARD_USERNAME,
password: process.env.DASHBOARD_PASSWORD,
},
};
}
const validLogLevels = ['debug', 'info', 'warn', 'error'];
if (process.env.LOG_LEVEL) {
if (!validLogLevels.includes(process.env.LOG_LEVEL)) {

View file

@ -27,12 +27,13 @@ async function analyzeOne(target: string) {
initLogger(config.logging);
const logger = getLogger();
initGitHub(process.env.GITHUB_TOKEN);
if (!process.env.GITHUB_TOKEN) {
logger.error('GITHUB_TOKEN is required for analyze mode');
process.exit(1);
}
initGitHub(process.env.GITHUB_TOKEN);
const prData = await fetchPR(owner, repo, prNumber);
if (!prData) {
logger.error(`Could not fetch PR ${owner}/${repo}#${prNumber}`);
@ -108,8 +109,9 @@ function serve() {
.filter(([, v]) => v.enabled)
.map(([k]) => k);
const server = app.listen(port, async () => {
logger.info(`Troutbot listening on port ${port}`);
const host = config.server.host || '127.0.0.1';
const server = app.listen(port, host, async () => {
logger.info(`Troutbot listening on ${host}:${port}`);
logger.info(`Enabled backends: ${enabledBackends.join(', ')}`);
// Watched repos
@ -140,7 +142,8 @@ function serve() {
// Comment update mode
logger.info(`Comment updates: ${config.response.allowUpdates ? 'enabled' : 'disabled'}`);
logger.info(`Dashboard available at http://localhost:${port}/dashboard`);
const displayHost = host === '0.0.0.0' ? 'localhost' : host;
logger.info(`Dashboard available at http://${displayHost}:${port}/dashboard`);
// Start polling if enabled
await startPolling(config);

View file

@ -1,5 +1,6 @@
export interface Config {
server: ServerConfig;
dashboard?: DashboardConfig;
repositories: RepoConfig[];
filters: FiltersConfig;
engine: EngineConfig;
@ -16,9 +17,22 @@ export interface PollingConfig {
export interface ServerConfig {
port: number;
host?: string;
rateLimit?: number;
}
export interface DashboardConfig {
enabled: boolean;
auth?: DashboardAuthConfig;
}
export interface DashboardAuthConfig {
type: 'basic' | 'token';
username?: string;
password?: string;
token?: string;
}
export interface RepoConfig {
owner: string;
repo: string;