Improve .env (#20)
* describeFeedGenerator route + multiple feeds * tweak readme * improve env
This commit is contained in:
parent
3606414b79
commit
745023cfc2
12
.env.example
12
.env.example
@ -1,4 +1,14 @@
|
||||
# Whichever port you want to run this on
|
||||
FEEDGEN_PORT=3000
|
||||
|
||||
# Set to something like db.sqlite to store persistently
|
||||
FEEDGEN_SQLITE_LOCATION=":memory:"
|
||||
|
||||
# Don't change unless you're working in a different environment than the primary Bluesky network
|
||||
FEEDGEN_SUBSCRIPTION_ENDPOINT="wss://bsky.social"
|
||||
FEEDGEN_SERVICE_DID="did:example:test"
|
||||
|
||||
# Set this to the hostname that you intend to run the service at
|
||||
FEEDGEN_HOSTNAME="example.com"
|
||||
|
||||
# Only use this if you want a service did different from did:web
|
||||
# FEEDGEN_SERVICE_DID="did:plc:abcde..."
|
14
src/index.ts
14
src/index.ts
@ -3,11 +3,17 @@ 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),
|
||||
sqliteLocation: maybeStr(process.env.FEEDGEN_SQLITE_LOCATION),
|
||||
subscriptionEndpoint: maybeStr(process.env.FEEDGEN_SUBSCRIPTION_ENDPOINT),
|
||||
serviceDid: maybeStr(process.env.FEEDGEN_SERVICE_DID),
|
||||
port: maybeInt(process.env.FEEDGEN_PORT) ?? 3000,
|
||||
sqliteLocation: maybeStr(process.env.FEEDGEN_SQLITE_LOCATION) ?? ':memory:',
|
||||
subscriptionEndpoint:
|
||||
maybeStr(process.env.FEEDGEN_SUBSCRIPTION_ENDPOINT) ??
|
||||
'wss://bsky.social',
|
||||
hostname,
|
||||
serviceDid,
|
||||
})
|
||||
await server.start()
|
||||
console.log(
|
||||
|
@ -29,14 +29,7 @@ export class FeedGenerator {
|
||||
this.cfg = cfg
|
||||
}
|
||||
|
||||
static create(config?: Partial<Config>) {
|
||||
const cfg: Config = {
|
||||
port: config?.port ?? 3000,
|
||||
hostname: config?.hostname ?? 'feed-generator.test',
|
||||
sqliteLocation: config?.sqliteLocation ?? ':memory:',
|
||||
subscriptionEndpoint: config?.subscriptionEndpoint ?? 'wss://bsky.social',
|
||||
serviceDid: config?.serviceDid ?? 'did:example:test',
|
||||
}
|
||||
static create(cfg: Config) {
|
||||
const app = express()
|
||||
const db = createDb(cfg.sqliteLocation)
|
||||
const firehose = new FirehoseSubscription(db, cfg.subscriptionEndpoint)
|
||||
@ -63,7 +56,7 @@ export class FeedGenerator {
|
||||
feedGeneration(server, ctx)
|
||||
describeGenerator(server, ctx)
|
||||
app.use(server.xrpc.router)
|
||||
app.use(wellKnown(cfg.hostname))
|
||||
app.use(wellKnown(ctx))
|
||||
|
||||
return new FeedGenerator(app, db, firehose, cfg)
|
||||
}
|
||||
|
@ -1,17 +1,21 @@
|
||||
import express from 'express'
|
||||
import { AppContext } from './config'
|
||||
|
||||
const makeRouter = (serverHostname: string) => {
|
||||
const makeRouter = (ctx: AppContext) => {
|
||||
const router = express.Router()
|
||||
|
||||
router.get('/.well-known/did.json', (_req, res) => {
|
||||
if (!ctx.cfg.serviceDid.endsWith(ctx.cfg.hostname)) {
|
||||
return res.sendStatus(404)
|
||||
}
|
||||
res.json({
|
||||
'@context': ['https://www.w3.org/ns/did/v1'],
|
||||
id: `did:web:${serverHostname}`,
|
||||
id: ctx.cfg.serviceDid,
|
||||
service: [
|
||||
{
|
||||
id: '#bsky_fg',
|
||||
type: 'BskyFeedGenerator',
|
||||
serviceEndpoint: `https://${serverHostname}`,
|
||||
serviceEndpoint: `https://${ctx.cfg.hostname}`,
|
||||
},
|
||||
],
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user