From e849ac7f666d4e4e3099f0adac13e441ae3e94be Mon Sep 17 00:00:00 2001 From: Ben Harris Date: Wed, 24 May 2023 18:53:37 -0400 Subject: [PATCH] add listenhost option (#28) (cherry picked from commit 1b2f04af6af57b36e800903b943aa4e01023b341) --- .env.example | 3 +++ src/config.ts | 1 + src/index.ts | 3 ++- src/server.ts | 2 +- 4 files changed, 7 insertions(+), 2 deletions(-) diff --git a/.env.example b/.env.example index 4cfdab3..49f71dc 100644 --- a/.env.example +++ b/.env.example @@ -1,6 +1,9 @@ # Whichever port you want to run this on FEEDGEN_PORT=3000 +# Change this to use a different bind address +FEEDGEN_LISTENHOST="localhost" + # Set to something like db.sqlite to store persistently FEEDGEN_SQLITE_LOCATION=":memory:" diff --git a/src/config.ts b/src/config.ts index 0ad8535..98c22e6 100644 --- a/src/config.ts +++ b/src/config.ts @@ -9,6 +9,7 @@ export type AppContext = { export type Config = { port: number + listenhost: string hostname: string sqliteLocation: string subscriptionEndpoint: string diff --git a/src/index.ts b/src/index.ts index 4960044..aa34a97 100644 --- a/src/index.ts +++ b/src/index.ts @@ -8,6 +8,7 @@ const run = async () => { maybeStr(process.env.FEEDGEN_SERVICE_DID) ?? `did:web:${hostname}` const server = FeedGenerator.create({ port: maybeInt(process.env.FEEDGEN_PORT) ?? 3000, + listenhost: maybeStr(process.env.FEEDGEN_LISTENHOST) ?? 'localhost', sqliteLocation: maybeStr(process.env.FEEDGEN_SQLITE_LOCATION) ?? ':memory:', subscriptionEndpoint: maybeStr(process.env.FEEDGEN_SUBSCRIPTION_ENDPOINT) ?? @@ -17,7 +18,7 @@ const run = async () => { }) await server.start() console.log( - `🤖 running feed generator at http://localhost:${server.cfg.port}`, + `🤖 running feed generator at http://${server.cfg.listenhost}:${server.cfg.port}`, ) } diff --git a/src/server.ts b/src/server.ts index 4e1449c..90a227b 100644 --- a/src/server.ts +++ b/src/server.ts @@ -64,7 +64,7 @@ export class FeedGenerator { async start(): Promise { await migrateToLatest(this.db) this.firehose.run() - this.server = this.app.listen(this.cfg.port) + this.server = this.app.listen(this.cfg.port, this.cfg.listenhost) await events.once(this.server, 'listening') return this.server }