add listenhost option (#28)

(cherry picked from commit 1b2f04af6af57b36e800903b943aa4e01023b341)
This commit is contained in:
Ben Harris 2023-05-24 18:53:37 -04:00 committed by GitHub
parent 51ca4d0659
commit e849ac7f66
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 7 additions and 2 deletions

View File

@ -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:"

View File

@ -9,6 +9,7 @@ export type AppContext = {
export type Config = {
port: number
listenhost: string
hostname: string
sqliteLocation: string
subscriptionEndpoint: string

View File

@ -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}`,
)
}

View File

@ -64,7 +64,7 @@ export class FeedGenerator {
async start(): Promise<http.Server> {
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
}