forked from bluesky-social/feed-generator
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.ts
41 lines (37 loc) · 1.21 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import dotenv from 'dotenv'
import FeedGenerator from './server'
const run = async () => {
dotenv.config()
const hostname = maybeStr(process.env.FEEDGEN_HOSTNAME) ?? 'example.com'
const serviceDid =
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) ??
'wss://bsky.network',
publisherDid:
maybeStr(process.env.FEEDGEN_PUBLISHER_DID) ?? 'did:example:alice',
subscriptionReconnectDelay:
maybeInt(process.env.FEEDGEN_SUBSCRIPTION_RECONNECT_DELAY) ?? 3000,
hostname,
serviceDid,
})
await server.start()
console.log(
`🤖 running feed generator at http://${server.cfg.listenhost}:${server.cfg.port}`,
)
}
const maybeStr = (val?: string) => {
if (!val) return undefined
return val
}
const maybeInt = (val?: string) => {
if (!val) return undefined
const int = parseInt(val, 10)
if (isNaN(int)) return undefined
return int
}
run()