Config by environment vars (#5)

* Support .env file

* Fix default sub endpoint
This commit is contained in:
devin ivy 2023-05-10 23:59:50 -04:00 committed by GitHub
parent 8ae277ffd4
commit 50f764ba86
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 28 additions and 5 deletions

1
.gitignore vendored
View File

@ -1 +1,2 @@
node_modules
.env

View File

@ -14,6 +14,7 @@
"@atproto/uri": "^0.0.2",
"@atproto/xrpc-server": "^0.1.0",
"better-sqlite3": "^8.3.0",
"dotenv": "^16.0.3",
"express": "^4.18.2",
"kysely": "^0.22.0"
},

View File

@ -1,10 +1,27 @@
import dotenv from 'dotenv'
import FeedGenerator from './server'
const run = async () => {
// we'll add .env soon
const server = FeedGenerator.create()
dotenv.config()
const server = FeedGenerator.create({
port: maybeInt(process.env.FEEDGEN_PORT),
sqliteLocation: maybeStr(process.env.FEEDGEN_SQLITE_LOCATION),
subscriptionEndpoint: maybeStr(process.env.FEEDGEN_SUBSCRIPTION_ENDPOINT),
})
await server.start()
console.log(`🤖 running feed generator at localhost${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()

View File

@ -35,8 +35,7 @@ export class FeedGenerator {
const cfg = {
port: config?.port ?? 3000,
sqliteLocation: config?.sqliteLocation ?? 'test.sqlite',
subscriptionEndpoint:
config?.subscriptionEndpoint ?? 'https://bsky.social',
subscriptionEndpoint: config?.subscriptionEndpoint ?? 'wss://bsky.social',
}
const app = express()
const db = createDb(cfg.sqliteLocation)

View File

@ -517,6 +517,11 @@ diff@^4.0.1:
resolved "https://registry.yarnpkg.com/diff/-/diff-4.0.2.tgz#60f3aecb89d5fae520c11aa19efc2bb982aade7d"
integrity sha512-58lmxKSA4BNyLz+HHMUzlOEpg09FV+ev6ZMe3vJihgdxzgcwZ8VoEEPmALCZG9LmqfVoNMMKpttIYTVG6uDY7A==
dotenv@^16.0.3:
version "16.0.3"
resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-16.0.3.tgz#115aec42bac5053db3c456db30cc243a5a836a07"
integrity sha512-7GO6HghkA5fYG9TYnNxi14/7K9f5occMlp3zXAuSxn7CKCxt9xbNWG7yF8hTCSUchlfWSe3uLmlPfigevRItzQ==
ee-first@1.1.1:
version "1.1.1"
resolved "https://registry.yarnpkg.com/ee-first/-/ee-first-1.1.1.tgz#590c61156b0ae2f4f0255732a158b266bc56b21d"