Skip to content

Commit

Permalink
feat: change default port to 32000
Browse files Browse the repository at this point in the history
  • Loading branch information
JacobLinCool committed May 15, 2023
1 parent 0ffe3f6 commit fed2746
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ categories = ["command-line-utilities"]
readme = "README.md"
license = "MIT"
edition = "2021"
include = ["/src", "build.rs", "LICENSE"]
include = ["/src", "build.rs", "LICENSE", "stdlib/"]

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

Expand All @@ -21,6 +21,7 @@ path = "src/main.rs"
base64 = "0.21.0"
clap = { version = "4.2.7", features = ["derive"] }
jsonwebtoken = "8.3.0"
rand = "0.8.5"
rocket = { version = "0.5.0-rc.3", features = ["json"] }
sha256 = "1.1.3"
shadow-rs = "0.21.0"
Expand Down
27 changes: 26 additions & 1 deletion src/server.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
use std::net::Ipv4Addr;
use std::path::PathBuf;

use rocket::serde::{json::Json, Deserialize, Serialize};
use rocket::Build;
use rocket::Config;
use rocket::Rocket;

use crate::cli::build;
use crate::compile;
use crate::jwt;
use crate::system;
Expand All @@ -14,18 +16,41 @@ fn index() -> &'static str {
"I am Compilet."
}

#[derive(Debug, Serialize, Deserialize)]
#[serde(crate = "rocket::serde")]
pub struct ServerInfo {
pub version: String,
pub commit: String,
pub build_time: String,
pub os: String,
}

#[get("/info")]
fn info() -> Json<ServerInfo> {
Json(ServerInfo {
version: build::PKG_VERSION.to_string(),
commit: build::COMMIT_HASH.to_string(),
build_time: build::BUILD_TIME.to_string(),
os: build::BUILD_OS.to_string(),
})
}

/// Get the Rocket instance
pub fn rocket() -> Rocket<Build> {
rocket::build()
.configure(Config {
address: Ipv4Addr::new(0, 0, 0, 0).into(),
port: std::env::var("PORT")
.unwrap_or_else(|_| "32000".to_string())
.parse()
.unwrap(),
..Config::default()
})
.manage(compile::WasmCache {
dir: PathBuf::from("cache"),
})
.mount(
"/",
routes![index, system::system, compile::compile, jwt::validate],
routes![index, info, system::system, compile::compile, jwt::validate],
)
}

0 comments on commit fed2746

Please sign in to comment.