mirror of
https://github.com/redlib-org/redlib.git
synced 2025-06-08 07:37:45 +00:00
Implement instance info endpoint (JSON, YAML, TXT) (#685)
Co-authored-by: Daniel Valentine <daniel@vielle.ws> Co-authored-by: spikecodes <19519553+spikecodes@users.noreply.github.com>
This commit is contained in:
parent
7efa26e811
commit
8be5fdee2d
11 changed files with 348 additions and 23 deletions
13
src/main.rs
13
src/main.rs
|
@ -5,6 +5,7 @@
|
|||
// Reference local files
|
||||
mod config;
|
||||
mod duplicates;
|
||||
mod instance_info;
|
||||
mod post;
|
||||
mod search;
|
||||
mod settings;
|
||||
|
@ -20,6 +21,7 @@ use hyper::{header::HeaderValue, Body, Request, Response};
|
|||
|
||||
mod client;
|
||||
use client::{canonical_path, proxy};
|
||||
use once_cell::sync::Lazy;
|
||||
use server::RequestExt;
|
||||
use utils::{error, redirect, ThemeAssets};
|
||||
|
||||
|
@ -158,6 +160,13 @@ async fn main() {
|
|||
// Begin constructing a server
|
||||
let mut app = server::Server::new();
|
||||
|
||||
// Force evaluation of statics. In instance_info case, we need to evaluate
|
||||
// the timestamp so deploy date is accurate - in config case, we need to
|
||||
// evaluate the configuration to avoid paying penalty at first request.
|
||||
|
||||
Lazy::force(&config::CONFIG);
|
||||
Lazy::force(&instance_info::INSTANCE_INFO);
|
||||
|
||||
// Define default headers (added to all responses)
|
||||
app.default_headers = headers! {
|
||||
"Referrer-Policy" => "no-referrer",
|
||||
|
@ -285,6 +294,10 @@ async fn main() {
|
|||
// Handle about pages
|
||||
app.at("/about").get(|req| error(req, "About pages aren't added yet".to_string()).boxed());
|
||||
|
||||
// Instance info page
|
||||
app.at("/info").get(|r| instance_info::instance_info(r).boxed());
|
||||
app.at("/info.:extension").get(|r| instance_info::instance_info(r).boxed());
|
||||
|
||||
app.at("/:id").get(|req: Request<Body>| {
|
||||
Box::pin(async move {
|
||||
match req.param("id").as_deref() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue