diff --git a/.gitignore b/.gitignore index b512c09..37d7e73 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ -node_modules \ No newline at end of file +node_modules +.env diff --git a/package.json b/package.json index cf61c16..72a4e97 100644 --- a/package.json +++ b/package.json @@ -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" }, diff --git a/src/index.ts b/src/index.ts index b8bbe81..8770d69 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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() diff --git a/src/server.ts b/src/server.ts index f86fd55..9b59d75 100644 --- a/src/server.ts +++ b/src/server.ts @@ -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) diff --git a/yarn.lock b/yarn.lock index b2e8e28..781bace 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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"