M main.tcl => main.tcl +19 -5
@@ 62,15 62,29 @@ db_cleanup [::ini::value $config database cleanup_interval] [::ini::value $confi
jetstream::listen [::ini::value $config atproto jetstream_host] $::algos::list
### HTTPD ###
-httpd::router main [list \
- /xrpc/app.bsky.feed.getFeedSkeleton [list ::feed::serve_skeleton \
+
+set routes {}
+
+set well_known [
+ ::feed::well_known \
$::algos::list \
- [::ini::value $config atproto publisher_did]] \
- /xrpc/app.bsky.feed.describeFeedGenerator [list ::feed::serve_generator_description \
+ [::ini::value $config atproto self_host]]
+lappend routes /.well-known/did.json \
+ [list ::httpd::serve application/json $well_known]
+
+lappend routes /xrpc/app.bsky.feed.getFeedSkeleton \
+ [list ::feed::serve_skeleton $::algos::list [::ini::value $config atproto publisher_did]]
+
+set generator_description [
+ ::feed::generator_description \
$::algos::list \
[::ini::value $config atproto publisher_did] \
[::ini::value $config atproto self_host]]
-]
+lappend /xrpc/app.bsky.feed.describeFeedGenerator \
+ [list ::httpd::serve application/json $generator_description]]
+
+httpd::router main $routes
+
httpd::listen main [::ini::value $config httpd port]
vwait nil
M src/feed.tcl => src/feed.tcl +13 -9
@@ 76,7 76,7 @@ namespace eval feed {
return
}
- proc ::feed::serve_generator_description {feeds publisher self_host _ sock path query headers} {
+ proc ::feed::generator_description {feeds publisher self_host} {
set feed_uris {}
foreach feed $feeds {
lappend feed_uris [::json::write object \
@@ 87,13 87,17 @@ namespace eval feed {
did [::json::write string "did:web:$self_host"] \
feeds $feed_uris]
- puts $sock "HTTP/1.0 200 OK"
- puts $sock "Content-Type: application/json"
- puts $sock "Content-Length: [string length $description]"
- puts $sock ""
- fconfigure $sock -translation binary
- puts -nonewline $sock $description
- close $sock
- return
+ return $description
+ }
+
+ proc ::feed::well_known {feeds self_host} {
+ ::json::write object \
+ @context {["https://www.w3.org/ns/did/v1"]} \
+ id [::json::write string did:web:$self_host] \
+ service [::json::write array \
+ [::json::write object \
+ id {"#bsky_fg"} \
+ serviceEndpoint [::json::write string https://$self_host] \
+ type {"BskyFeedGenerator"}]]
}
}
M src/httpd.tcl => src/httpd.tcl +10 -0
@@ 79,4 79,14 @@ namespace eval ::httpd {
flush $sock
close $sock
}
+
+ proc ::httpd::serve {mime payload _ sock _ _ _} {
+ puts $sock "HTTP/1.0 200 OK"
+ puts $sock "Content-Type: $mime"
+ puts $sock "Content-Length: [string length $payload]"
+ puts $sock ""
+ fconfigure $sock -translation binary
+ puts -nonewline $sock $payload
+ close $sock
+ }
}