Skip to content

Commit

Permalink
feat: add version headers
Browse files Browse the repository at this point in the history
  • Loading branch information
JacobLinCool committed Jun 4, 2023
1 parent bdac5c4 commit 21ac4dd
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 6 deletions.
11 changes: 7 additions & 4 deletions src/server/core.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use super::compress;
use super::execute;
use super::judge;
use super::jwt;
use super::version;
use crate::config::*;
use crate::server::compress;
use crate::server::execute;
use crate::server::judge;
use crate::server::jwt;
use rocket::data::ByteUnit;
use rocket::serde::{json::Json, Deserialize, Serialize};
use rocket::Build;
Expand Down Expand Up @@ -51,6 +52,8 @@ pub fn rocket() -> Rocket<Build> {
routes![index, info, jwt::validate, execute::execute, judge::judge],
);

let server = server.attach(version::fairing());

if cfg!(debug_assertions) {
server
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/server/execute.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use super::jwt;
use crate::config::*;
use crate::run;
use crate::server::jwt;
use base64::{engine::general_purpose, Engine as _};
use rocket::serde::{
json::{Error, Json},
Expand Down
2 changes: 1 addition & 1 deletion src/server/judge.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use super::jwt;
use crate::judger::{Input, JudgeSpec, Judger, Output};
use crate::run;
use crate::server::jwt;
use base64::engine::general_purpose;
use base64::Engine;
use reqwest::Client;
Expand Down
1 change: 1 addition & 0 deletions src/server/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ pub mod core;
mod execute;
mod judge;
mod jwt;
mod version;
13 changes: 13 additions & 0 deletions src/server/version.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
use rocket::{fairing::AdHoc, http::Header};

pub fn fairing() -> AdHoc {
AdHoc::on_response("Version Headers", |_req, res| {
Box::pin(async move {
res.set_header(Header::new(
"X-Powered-By",
"WARK (https://github.com/wasm-oj/wark)",
));
res.set_header(Header::new("X-Version", env!("VERGEN_GIT_DESCRIBE")));
})
})
}

0 comments on commit 21ac4dd

Please sign in to comment.