tangled
alpha
login
or
join now
microcosm.blue
/
microcosm-rs
65
fork
atom
Constellation, Spacedust, Slingshot, UFOs: atproto crates and services for microcosm
65
fork
atom
overview
issues
8
pulls
2
pipelines
serve a did web!
bad-example.com
1 month ago
e679c6e1
b636480a
+39
-8
2 changed files
expand all
collapse all
unified
split
constellation
src
bin
main.rs
server
mod.rs
+7
-1
constellation/src/bin/main.rs
···
45
#[arg(short, long)]
46
#[clap(value_enum, default_value_t = StorageBackend::Memory)]
47
backend: StorageBackend,
0
0
0
48
/// Initiate a database backup into this dir, if supported by the storage
49
#[arg(long)]
50
backup: Option<PathBuf>,
···
103
MemStorage::new(),
104
fixture,
105
None,
0
106
stream,
107
bind,
108
metrics_bind,
···
138
rocks,
139
fixture,
140
args.data,
0
141
stream,
142
bind,
143
metrics_bind,
···
159
mut storage: impl LinkStorage,
160
fixture: Option<PathBuf>,
161
data_dir: Option<PathBuf>,
0
162
stream: String,
163
bind: SocketAddr,
164
metrics_bind: SocketAddr,
···
211
if collect_metrics {
212
install_metrics_server(metrics_bind)?;
213
}
214
-
serve(readable, bind, staying_alive).await
215
})
216
.unwrap();
217
stay_alive.drop_guard();
···
45
#[arg(short, long)]
46
#[clap(value_enum, default_value_t = StorageBackend::Memory)]
47
backend: StorageBackend,
48
+
/// Serve a did:web document for this domain
49
+
#[arg(long)]
50
+
did_web_domain: Option<String>,
51
/// Initiate a database backup into this dir, if supported by the storage
52
#[arg(long)]
53
backup: Option<PathBuf>,
···
106
MemStorage::new(),
107
fixture,
108
None,
109
+
args.did_web_domain,
110
stream,
111
bind,
112
metrics_bind,
···
142
rocks,
143
fixture,
144
args.data,
145
+
args.did_web_domain,
146
stream,
147
bind,
148
metrics_bind,
···
164
mut storage: impl LinkStorage,
165
fixture: Option<PathBuf>,
166
data_dir: Option<PathBuf>,
167
+
did_web_domain: Option<String>,
168
stream: String,
169
bind: SocketAddr,
170
metrics_bind: SocketAddr,
···
217
if collect_metrics {
218
install_metrics_server(metrics_bind)?;
219
}
220
+
serve(readable, bind, did_web_domain, staying_alive).await
221
})
222
.unwrap();
223
stay_alive.drop_guard();
+32
-7
constellation/src/server/mod.rs
···
3
extract::{Query, Request},
4
http::{self, header},
5
middleware::{self, Next},
6
-
response::{IntoResponse, Response},
7
routing::get,
8
Router,
9
};
···
37
http::StatusCode::INTERNAL_SERVER_ERROR
38
}
39
40
-
pub async fn serve<S, A>(store: S, addr: A, stay_alive: CancellationToken) -> anyhow::Result<()>
41
-
where
42
-
S: LinkReader,
43
-
A: ToSocketAddrs,
44
-
{
45
-
let app = Router::new()
0
0
0
0
0
0
0
0
0
0
0
0
0
46
.route("/robots.txt", get(robots))
47
.route(
48
"/",
···
204
User-agent: *
205
Disallow: /links
206
Disallow: /links/
0
207
"
0
0
0
0
0
0
0
0
0
0
0
208
}
209
210
#[derive(Template, Serialize, Deserialize)]
···
3
extract::{Query, Request},
4
http::{self, header},
5
middleware::{self, Next},
6
+
response::{IntoResponse, Json, Response},
7
routing::get,
8
Router,
9
};
···
37
http::StatusCode::INTERNAL_SERVER_ERROR
38
}
39
40
+
pub async fn serve<S: LinkReader, A: ToSocketAddrs>(
41
+
store: S,
42
+
addr: A,
43
+
did_web_domain: Option<String>,
44
+
stay_alive: CancellationToken,
45
+
) -> anyhow::Result<()> {
46
+
let mut app = Router::new();
47
+
48
+
if let Some(d) = did_web_domain {
49
+
app = app.route(
50
+
"/.well-known/did.json",
51
+
get({
52
+
let domain = d.clone();
53
+
move || did_web(domain)
54
+
}),
55
+
)
56
+
}
57
+
58
+
let app = app
59
.route("/robots.txt", get(robots))
60
.route(
61
"/",
···
217
User-agent: *
218
Disallow: /links
219
Disallow: /links/
220
+
Disallow: /xrpc/
221
"
222
+
}
223
+
224
+
async fn did_web(domain: String) -> impl IntoResponse {
225
+
Json(serde_json::json!({
226
+
"id": format!("did:web:{domain}"),
227
+
"service": [{
228
+
"id": "#constellation",
229
+
"type": "ConstellationGraphService",
230
+
"serviceEndpoint": format!("https://{domain}")
231
+
}]
232
+
}))
233
}
234
235
#[derive(Template, Serialize, Deserialize)]