feat: added a relay for gatus statuses and changes the url it uses
This commit is contained in:
		
							parent
							
								
									39134b5229
								
							
						
					
					
						commit
						43d05fadc4
					
				
					 8 changed files with 1910 additions and 4 deletions
				
			
		
							
								
								
									
										1
									
								
								.dockerignore
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								.dockerignore
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1 @@ | ||||||
|  | target/ | ||||||
							
								
								
									
										1
									
								
								.gitignore
									
										
									
									
										vendored
									
									
								
							
							
						
						
									
										1
									
								
								.gitignore
									
										
									
									
										vendored
									
									
								
							|  | @ -1 +1,2 @@ | ||||||
| .vscode | .vscode | ||||||
|  | /target | ||||||
|  |  | ||||||
							
								
								
									
										1834
									
								
								Cargo.lock
									
										
									
										generated
									
									
									
										Normal file
									
								
							
							
						
						
									
										1834
									
								
								Cargo.lock
									
										
									
										generated
									
									
									
										Normal file
									
								
							
										
											
												File diff suppressed because it is too large
												Load diff
											
										
									
								
							
							
								
								
									
										12
									
								
								Cargo.toml
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										12
									
								
								Cargo.toml
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,12 @@ | ||||||
|  | [package] | ||||||
|  | name = "ixvd-web" | ||||||
|  | version = "0.1.0" | ||||||
|  | edition = "2021" | ||||||
|  | 
 | ||||||
|  | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||||||
|  | 
 | ||||||
|  | [dependencies] | ||||||
|  | actix-web = "4" | ||||||
|  | actix-files = "0.6.2" | ||||||
|  | reqwest = "0.11.18" | ||||||
|  | env_logger = "0.10.0" | ||||||
							
								
								
									
										17
									
								
								Dockerfile
									
										
									
									
									
								
							
							
						
						
									
										17
									
								
								Dockerfile
									
										
									
									
									
								
							|  | @ -1,3 +1,16 @@ | ||||||
| FROM nginx | FROM rust | ||||||
| 
 | 
 | ||||||
| COPY public /usr/share/nginx/html | WORKDIR /usr/src/app | ||||||
|  | 
 | ||||||
|  | # first cargo files to cache dependencies | ||||||
|  | COPY Cargo.toml Cargo.lock ./ | ||||||
|  | RUN mkdir src && \ | ||||||
|  |     echo "fn main() {println!(\"if you see this, the build broke\")}" > src/main.rs && \ | ||||||
|  |     cargo build --release | ||||||
|  | RUN rm -rf src target/release/deps/ixvd_web* | ||||||
|  | 
 | ||||||
|  | COPY . . | ||||||
|  | RUN cargo build --release | ||||||
|  | 
 | ||||||
|  | EXPOSE 8080 | ||||||
|  | CMD ["./target/release/ixvd-web"] | ||||||
|  | @ -9,7 +9,7 @@ const serviceHolderDiv = document.querySelector('#service-holder'); | ||||||
| 
 | 
 | ||||||
| async function update() { | async function update() { | ||||||
|     serviceHolderDiv.innerHTML = 'Loading...'; |     serviceHolderDiv.innerHTML = 'Loading...'; | ||||||
|     let fetchResult = await (await fetch('https://s.ixvd.net/api/v1/endpoints/statuses')).json() |     let fetchResult = await (await fetch('/relay/gatus')).json() | ||||||
|     serviceHolderDiv.innerHTML = ''; |     serviceHolderDiv.innerHTML = ''; | ||||||
| 
 | 
 | ||||||
|     fetchResult.forEach(s => { |     fetchResult.forEach(s => { | ||||||
|  |  | ||||||
							
								
								
									
										23
									
								
								src/main.rs
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										23
									
								
								src/main.rs
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,23 @@ | ||||||
|  | use actix_files as fs; | ||||||
|  | use actix_web::{App, HttpServer, middleware}; | ||||||
|  | use env_logger; | ||||||
|  | 
 | ||||||
|  | mod relay; | ||||||
|  | 
 | ||||||
|  | #[actix_web::main] | ||||||
|  | async fn main() -> std::io::Result<()> { | ||||||
|  |     env_logger::init_from_env(env_logger::Env::default().default_filter_or("info")); | ||||||
|  | 
 | ||||||
|  |     HttpServer::new(|| { | ||||||
|  |         App::new() | ||||||
|  |             .wrap(middleware::Logger::default()) | ||||||
|  |             .configure(relay::configure) | ||||||
|  |             .service( | ||||||
|  |                 fs::Files::new("/", "./public/") | ||||||
|  |                     .index_file("index.html") | ||||||
|  |             ) | ||||||
|  |     }) | ||||||
|  |         .bind(("0.0.0.0", 8080))? | ||||||
|  |         .run() | ||||||
|  |         .await | ||||||
|  | } | ||||||
							
								
								
									
										22
									
								
								src/relay.rs
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										22
									
								
								src/relay.rs
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,22 @@ | ||||||
|  | use actix_web::{HttpResponse, web, get}; | ||||||
|  | use actix_web::http::StatusCode; | ||||||
|  | 
 | ||||||
|  | #[get("/gatus")] | ||||||
|  | pub async fn get_gatus_services() -> HttpResponse { | ||||||
|  |     let status_response = if let Ok(res) = reqwest::get("https://s.ixvd.net/api/v1/endpoints/statuses").await { | ||||||
|  |         res | ||||||
|  |     } else { | ||||||
|  |         return HttpResponse::build(StatusCode::INTERNAL_SERVER_ERROR) | ||||||
|  |             .body("Failed to get status from gatus"); | ||||||
|  |     }; | ||||||
|  | 
 | ||||||
|  |     HttpResponse::build(StatusCode::OK) | ||||||
|  |         .body(status_response.text().await.unwrap()) | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | pub fn configure(cfg: &mut web::ServiceConfig) { | ||||||
|  |     cfg.service( | ||||||
|  |         web::scope("/relay") | ||||||
|  |             .service(get_gatus_services) | ||||||
|  |     ); | ||||||
|  | } | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue