alpha
Login
or
Join now
microcosm.blue
/
microcosm-rs
Star
0
Fork
3
Atom
Configure Feed
Issues
Pull Requests
Commits
Tags
Feed URL
Select the types of activity you want to include in your feed.
Constellation, Spacedust, Slingshot, UFOs: atproto crates and services for microcosm
Star
0
Fork
3
Atom
Configure Feed
Issues
Pull Requests
Commits
Tags
Feed URL
Select the types of activity you want to include in your feed.
Overview
Issues
Pulls
Pipelines
serve openapi as the home page
author
phil
date
1 year ago
(May 7, 2025, 3:31 PM -0400)
commit
fd61d9a7
fd61d9a715833733b2282592fcae53aa4f8adabb
parent
faf1b8b2
faf1b8b277880fbe80c55ab1e255142ffb54148f
+57
5 changed files
Expand all
Collapse all
Unified
Split
Cargo.lock
ufos
Cargo.toml
src
index_html.rs
lib.rs
server.rs
+1
Cargo.lock
Reviewed
···
3808
3808
"dropshot",
3809
3809
"env_logger",
3810
3810
"fjall",
3811
3811
+
"http",
3811
3812
"jetstream",
3812
3813
"log",
3813
3814
"lsm-tree",
+1
ufos/Cargo.toml
Reviewed
···
12
12
dropshot = "0.16.0"
13
13
env_logger = "0.11.7"
14
14
fjall = { version = "2.8.0", features = ["lz4"] }
15
15
+
http = "1.3.1"
15
16
jetstream = { path = "../jetstream" }
16
17
log = "0.4.26"
17
18
lsm-tree = "2.6.6"
+29
ufos/src/index_html.rs
Reviewed
···
1
1
+
pub const INDEX_HTML: &str = r#"<!DOCTYPE html>
2
2
+
<html lang="en">
3
3
+
<head>
4
4
+
<meta charset="utf-8" />
5
5
+
<title>UFOs API Documentation</title>
6
6
+
<meta name="viewport" content="width=device-width, initial-scale=1" />
7
7
+
<meta name="description" content="API Documentation for UFOs: Samples and stats for all atproto lexicons." />
8
8
+
<link rel="stylesheet" href="https://unpkg.com/swagger-ui-dist@5.11.0/swagger-ui.css" />
9
9
+
</head>
10
10
+
<body>
11
11
+
<div id="swagger-ui"></div>
12
12
+
<script src="https://unpkg.com/swagger-ui-dist@5.11.0/swagger-ui-bundle.js" crossorigin></script>
13
13
+
<script src="https://unpkg.com/swagger-ui-dist@5.11.0/swagger-ui-standalone-preset.js" crossorigin></script>
14
14
+
<script>
15
15
+
window.onload = () => {
16
16
+
window.ui = SwaggerUIBundle({
17
17
+
url: '/openapi',
18
18
+
dom_id: '#swagger-ui',
19
19
+
presets: [
20
20
+
SwaggerUIBundle.presets.apis,
21
21
+
SwaggerUIStandalonePreset
22
22
+
],
23
23
+
layout: "StandaloneLayout",
24
24
+
});
25
25
+
};
26
26
+
</script>
27
27
+
</body>
28
28
+
</html>
29
29
+
"#;
+2
ufos/src/lib.rs
Reviewed
···
2
2
pub mod db_types;
3
3
pub mod error;
4
4
pub mod file_consumer;
5
5
+
pub mod index_html;
5
6
pub mod server;
6
7
pub mod storage;
7
8
pub mod storage_fjall;
···
212
213
}
213
214
214
215
#[derive(Debug, Serialize, JsonSchema)]
216
216
+
#[serde(rename_all = "camelCase")]
215
217
pub enum ConsumerInfo {
216
218
Jetstream {
217
219
endpoint: String,
+24
ufos/src/server.rs
Reviewed
···
1
1
+
use crate::index_html::INDEX_HTML;
1
2
use crate::storage::StoreReader;
2
3
use crate::{ConsumerInfo, Nsid, TopCollections, UFOsRecord};
3
4
use dropshot::endpoint;
4
5
use dropshot::ApiDescription;
6
6
+
use dropshot::Body;
5
7
use dropshot::ConfigDropshot;
6
8
use dropshot::ConfigLogging;
7
9
use dropshot::ConfigLoggingLevel;
···
11
13
use dropshot::Query;
12
14
use dropshot::RequestContext;
13
15
use dropshot::ServerBuilder;
16
16
+
use http::{Response, StatusCode};
14
17
use schemars::JsonSchema;
15
18
use serde::{Deserialize, Serialize};
16
19
use std::collections::HashMap;
···
21
24
storage: Box<dyn StoreReader>,
22
25
}
23
26
27
27
+
/// Serve index page as html
28
28
+
#[endpoint {
29
29
+
method = GET,
30
30
+
path = "/",
31
31
+
/*
32
32
+
* not useful to have this in openapi
33
33
+
*/
34
34
+
unpublished = true,
35
35
+
}]
36
36
+
async fn index(_ctx: RequestContext<Context>) -> Result<Response<Body>, HttpError> {
37
37
+
Ok(Response::builder()
38
38
+
.status(StatusCode::OK)
39
39
+
.header(http::header::CONTENT_TYPE, "text/html")
40
40
+
.body(INDEX_HTML.into())?)
41
41
+
}
42
42
+
24
43
/// Meta: get the openapi spec for this api
25
44
#[endpoint {
26
45
method = GET,
27
46
path = "/openapi",
47
47
+
/*
48
48
+
* not useful to have this in openapi
49
49
+
*/
50
50
+
unpublished = true,
28
51
}]
29
52
async fn get_openapi(ctx: RequestContext<Context>) -> OkCorsResponse<serde_json::Value> {
30
53
let spec = (*ctx.context().spec).clone();
···
214
237
215
238
let mut api = ApiDescription::new();
216
239
240
240
+
api.register(index).unwrap();
217
241
api.register(get_openapi).unwrap();
218
242
api.register(get_meta_info).unwrap();
219
243
api.register(get_records_by_collections).unwrap();