add did-web example
This commit is contained in:
parent
f9ccf112e1
commit
050047fcd0
@ -9,6 +9,7 @@ export type AppContext = {
|
||||
|
||||
export type Config = {
|
||||
port: number
|
||||
hostname: string
|
||||
sqliteLocation: string
|
||||
subscriptionEndpoint: string
|
||||
serviceDid: string
|
||||
|
@ -7,6 +7,7 @@ import feedGeneration from './feed-generation'
|
||||
import { createDb, Database, migrateToLatest } from './db'
|
||||
import { FirehoseSubscription } from './subscription'
|
||||
import { AppContext, Config } from './config'
|
||||
import wellKnown from './well-known'
|
||||
|
||||
export class FeedGenerator {
|
||||
public app: express.Application
|
||||
@ -30,6 +31,7 @@ export class FeedGenerator {
|
||||
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',
|
||||
@ -59,6 +61,7 @@ export class FeedGenerator {
|
||||
}
|
||||
feedGeneration(server, ctx)
|
||||
app.use(server.xrpc.router)
|
||||
app.use(wellKnown(cfg.hostname))
|
||||
|
||||
return new FeedGenerator(app, db, firehose, cfg)
|
||||
}
|
||||
|
22
src/well-known.ts
Normal file
22
src/well-known.ts
Normal file
@ -0,0 +1,22 @@
|
||||
import express from 'express'
|
||||
|
||||
const makeRouter = (serverHostname: string) => {
|
||||
const router = express.Router()
|
||||
|
||||
router.get('/.well-known/did.json', (_req, res) => {
|
||||
res.json({
|
||||
'@context': ['https://www.w3.org/ns/did/v1'],
|
||||
id: `did:web:${serverHostname}`,
|
||||
service: [
|
||||
{
|
||||
id: '#bsky_fg',
|
||||
type: 'BskyFeedGenerator',
|
||||
serviceEndpoint: `https://${serverHostname}`,
|
||||
},
|
||||
],
|
||||
})
|
||||
})
|
||||
|
||||
return router
|
||||
}
|
||||
export default makeRouter
|
Loading…
Reference in New Issue
Block a user