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
|
FEEDGEN_PORT=3000
|
||||||
|
|
||||||
|
# Set to something like db.sqlite to store persistently
|
||||||
FEEDGEN_SQLITE_LOCATION=":memory:"
|
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_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 () => {
|
const run = async () => {
|
||||||
dotenv.config()
|
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({
|
const server = FeedGenerator.create({
|
||||||
port: maybeInt(process.env.FEEDGEN_PORT),
|
port: maybeInt(process.env.FEEDGEN_PORT) ?? 3000,
|
||||||
sqliteLocation: maybeStr(process.env.FEEDGEN_SQLITE_LOCATION),
|
sqliteLocation: maybeStr(process.env.FEEDGEN_SQLITE_LOCATION) ?? ':memory:',
|
||||||
subscriptionEndpoint: maybeStr(process.env.FEEDGEN_SUBSCRIPTION_ENDPOINT),
|
subscriptionEndpoint:
|
||||||
serviceDid: maybeStr(process.env.FEEDGEN_SERVICE_DID),
|
maybeStr(process.env.FEEDGEN_SUBSCRIPTION_ENDPOINT) ??
|
||||||
|
'wss://bsky.social',
|
||||||
|
hostname,
|
||||||
|
serviceDid,
|
||||||
})
|
})
|
||||||
await server.start()
|
await server.start()
|
||||||
console.log(
|
console.log(
|
||||||
|
@ -29,14 +29,7 @@ export class FeedGenerator {
|
|||||||
this.cfg = cfg
|
this.cfg = cfg
|
||||||
}
|
}
|
||||||
|
|
||||||
static create(config?: Partial<Config>) {
|
static create(cfg: 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',
|
|
||||||
}
|
|
||||||
const app = express()
|
const app = express()
|
||||||
const db = createDb(cfg.sqliteLocation)
|
const db = createDb(cfg.sqliteLocation)
|
||||||
const firehose = new FirehoseSubscription(db, cfg.subscriptionEndpoint)
|
const firehose = new FirehoseSubscription(db, cfg.subscriptionEndpoint)
|
||||||
@ -63,7 +56,7 @@ export class FeedGenerator {
|
|||||||
feedGeneration(server, ctx)
|
feedGeneration(server, ctx)
|
||||||
describeGenerator(server, ctx)
|
describeGenerator(server, ctx)
|
||||||
app.use(server.xrpc.router)
|
app.use(server.xrpc.router)
|
||||||
app.use(wellKnown(cfg.hostname))
|
app.use(wellKnown(ctx))
|
||||||
|
|
||||||
return new FeedGenerator(app, db, firehose, cfg)
|
return new FeedGenerator(app, db, firehose, cfg)
|
||||||
}
|
}
|
||||||
|
@ -1,17 +1,21 @@
|
|||||||
import express from 'express'
|
import express from 'express'
|
||||||
|
import { AppContext } from './config'
|
||||||
|
|
||||||
const makeRouter = (serverHostname: string) => {
|
const makeRouter = (ctx: AppContext) => {
|
||||||
const router = express.Router()
|
const router = express.Router()
|
||||||
|
|
||||||
router.get('/.well-known/did.json', (_req, res) => {
|
router.get('/.well-known/did.json', (_req, res) => {
|
||||||
|
if (!ctx.cfg.serviceDid.endsWith(ctx.cfg.hostname)) {
|
||||||
|
return res.sendStatus(404)
|
||||||
|
}
|
||||||
res.json({
|
res.json({
|
||||||
'@context': ['https://www.w3.org/ns/did/v1'],
|
'@context': ['https://www.w3.org/ns/did/v1'],
|
||||||
id: `did:web:${serverHostname}`,
|
id: ctx.cfg.serviceDid,
|
||||||
service: [
|
service: [
|
||||||
{
|
{
|
||||||
id: '#bsky_fg',
|
id: '#bsky_fg',
|
||||||
type: 'BskyFeedGenerator',
|
type: 'BskyFeedGenerator',
|
||||||
serviceEndpoint: `https://${serverHostname}`,
|
serviceEndpoint: `https://${ctx.cfg.hostname}`,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user