File tree Expand file tree Collapse file tree 5 files changed +55
-54
lines changed Expand file tree Collapse file tree 5 files changed +55
-54
lines changed Original file line number Diff line number Diff line change @@ -6,7 +6,7 @@ use database::{background_task::BackgroundTask, PgDatabase};
66use figment:: providers:: { Format , Json } ;
77use rocket:: { catchers, fairing:: AdHoc , figment, routes} ;
88use rocket_db_pools:: Database ;
9- use routes:: { docs , health , pastes, security} ;
9+ use routes:: { meta , pastes, security} ;
1010use scanners:: InitScanners ;
1111
1212pub mod config;
@@ -21,11 +21,11 @@ pub mod utils;
2121#[ rocket:: launch]
2222fn rocket ( ) -> _ {
2323 let routes = routes ! [
24- routes:: get_root,
2524 cors:: snatcher,
26- docs:: get_docs,
27- docs:: get_spec,
28- health:: health,
25+ meta:: get_root,
26+ meta:: get_docs,
27+ meta:: get_spec,
28+ meta:: get_health,
2929 pastes:: get_paste,
3030 pastes:: create_paste_simple,
3131 pastes:: create_paste_structured,
Load Diff This file was deleted.
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 1+ use rocket:: {
2+ get,
3+ response:: {
4+ content:: { RawHtml , RawJson } ,
5+ Redirect ,
6+ } ,
7+ serde:: json:: Json ,
8+ uri,
9+ } ;
10+ use rocket_db_pools:: {
11+ sqlx:: { self , Row } ,
12+ Connection ,
13+ } ;
14+ use scalar_doc:: { Documentation , Theme } ;
15+
16+ use crate :: {
17+ database:: PgDatabase ,
18+ result:: { HTTPError , Result } ,
19+ } ;
20+
21+ #[ get( "/" ) ]
22+ pub fn get_root ( ) -> Redirect {
23+ Redirect :: temporary ( uri ! ( "/docs" ) )
24+ }
25+
26+ #[ get( "/docs" ) ]
27+ pub fn get_docs ( ) -> RawHtml < String > {
28+ let docs = Documentation :: new ( "MystBin API Documentation" , "/docs/spec.json" )
29+ . theme ( Theme :: Alternate )
30+ . build ( )
31+ . unwrap ( ) ;
32+
33+ RawHtml ( docs)
34+ }
35+
36+ #[ get( "/docs/spec.json" ) ]
37+ pub fn get_spec ( ) -> RawJson < & ' static str > {
38+ RawJson ( include_str ! ( "../../openapi.json" ) )
39+ }
40+
41+ #[ get( "/health" ) ]
42+ pub async fn get_health ( mut db : Connection < PgDatabase > ) -> Result < String > {
43+ let result = sqlx:: query ( "SELECT 'ok'" ) . fetch_one ( & mut * * db) . await ;
44+
45+ match result {
46+ Ok ( row) => Ok ( row. get ( 0 ) ) ,
47+ Err ( _) => Err ( HTTPError :: new ( 503 , "Database connection unhealthy." ) ) ,
48+ }
49+ }
Original file line number Diff line number Diff line change 1- use rocket:: { get, response:: Redirect , uri} ;
2-
3- pub mod docs;
4- pub mod health;
1+ pub mod meta;
52pub mod pastes;
63pub mod security;
7-
8- #[ get( "/" ) ]
9- pub fn get_root ( ) -> Redirect {
10- Redirect :: temporary ( uri ! ( "/docs" ) )
11- }
You can’t perform that action at this time.
0 commit comments