ソースを参照

Add configurable HOST option for server binding

- Add HOST configuration option in .env (default: 0.0.0.0)
- Update config.js to read HOST from environment
- Update server.js to bind to configured host
- Update .env.example with HOST setting
- Update README with HOST documentation and examples

This allows users to control which network interface the server binds to,
enabling localhost-only binding (127.0.0.1) or specific interface binding.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Claude (AgentBox) 9 ヶ月 前
コミット
5cca1fbc70
4 ファイル変更13 行追加4 行削除
  1. 1 0
      .env.example
  2. 6 0
      README.md
  3. 1 0
      src/config.js
  4. 5 4
      src/server.js

+ 1 - 0
.env.example

@@ -1,4 +1,5 @@
 # Server Configuration
+HOST=0.0.0.0
 PORT=3000
 WEBHOOK_PATH=/webhook
 WEBHOOK_SECRET=

+ 6 - 0
README.md

@@ -60,11 +60,17 @@ cp .env.example .env
 #### Basic Server Configuration
 
 ```env
+HOST=0.0.0.0
 PORT=3000
 WEBHOOK_PATH=/webhook
 WEBHOOK_SECRET=your-secret-here
 ```
 
+- `HOST` - The network interface to bind to (default: `0.0.0.0` for all interfaces, use `127.0.0.1` for localhost only)
+- `PORT` - The port number to listen on (default: `3000`)
+- `WEBHOOK_PATH` - The URL path for webhooks (default: `/webhook`)
+- `WEBHOOK_SECRET` - Optional secret for webhook verification
+
 #### Command Execution Configuration
 
 Configure commands to execute when webhooks are received. Commands support variable substitution:

+ 1 - 0
src/config.js

@@ -81,6 +81,7 @@ export class Config {
    */
   getServerConfig() {
     return {
+      host: this.get('HOST', '0.0.0.0'),
       port: this.getNumber('PORT', 3000),
       path: this.get('WEBHOOK_PATH', '/webhook'),
       secret: this.get('WEBHOOK_SECRET', null)

+ 5 - 4
src/server.js

@@ -7,6 +7,7 @@ import { WebhookHandler } from './webhookHandler.js';
 
 export class WebhookServer {
   constructor(options = {}) {
+    this.host = options.host || '0.0.0.0';
     this.port = options.port || 3000;
     this.path = options.path || '/webhook';
     this.secret = options.secret || null;
@@ -108,10 +109,10 @@ export class WebhookServer {
   start() {
     this.server = http.createServer((req, res) => this._handleRequest(req, res));
 
-    this.server.listen(this.port, () => {
-      logger.info(`Webhook server listening on port ${this.port}`);
-      logger.info(`Webhook endpoint: http://localhost:${this.port}${this.path}`);
-      logger.info(`Health check: http://localhost:${this.port}/health`);
+    this.server.listen(this.port, this.host, () => {
+      logger.info(`Webhook server listening on ${this.host}:${this.port}`);
+      logger.info(`Webhook endpoint: http://${this.host}:${this.port}${this.path}`);
+      logger.info(`Health check: http://${this.host}:${this.port}/health`);
     });
 
     return this;