From 6e51bd442843186602adc263c630beb6e16d1644 Mon Sep 17 00:00:00 2001 From: Mohammed Rabil Date: Wed, 7 Feb 2024 23:15:19 +0530 Subject: [PATCH] Add Rocket.toml and update Spacefile and main.rs --- Rocket.toml | 16 ++++++++++++++++ Spacefile | 3 ++- src/main.rs | 31 ++++--------------------------- 3 files changed, 22 insertions(+), 28 deletions(-) create mode 100644 Rocket.toml diff --git a/Rocket.toml b/Rocket.toml new file mode 100644 index 0000000..cf3cb6f --- /dev/null +++ b/Rocket.toml @@ -0,0 +1,16 @@ +## defaults for _all_ profiles +[default] +address = "0.0.0.0" +limits = { form = "64 kB", json = "1 MiB" } + +## set only when compiled in debug mode, i.e, `cargo build` +[debug] +port = 8001 +## only the `json` key from `default` will be overridden; `form` will remain +limits = { json = "10MiB" } + +## set only when compiled in release mode, i.e, `cargo build --release` +[release] +port = 9999 +ip_header = false +secret_key = "hPrYyЭRiMyµ5sBB1π+CMæ1køFsåqKvBiQJxBVHQk=" \ No newline at end of file diff --git a/Spacefile b/Spacefile index 2003017..1fa4e98 100644 --- a/Spacefile +++ b/Spacefile @@ -9,4 +9,5 @@ micros: - curl -Lo server --progress-bar http://github.com/prevanced/prevanced-backend/releases/latest/download/prevanced-backend run: ./server include: - - server \ No newline at end of file + - server + - Rocket.toml \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index 3da6c4a..12cfdcb 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,23 +1,5 @@ -#[macro_use] extern crate rocket; -use rocket::figment::{providers::{Env, Format, Serialized, Toml}, Figment, Profile}; -use serde::{Deserialize, Serialize}; - -#[derive(Debug, Deserialize, Serialize)] -struct Config { - port: u16, - /* and so on.. */ -} - -impl Default for Config { - fn default() -> Config { - let port_string: String = std::env::var("PORT").unwrap_or("8000".to_string()); - let port: u16 = port_string.parse().unwrap(); - Config { - port, - } - } -} - +#[macro_use] +extern crate rocket; #[get("/")] fn index() -> &'static str { @@ -26,10 +8,5 @@ fn index() -> &'static str { #[launch] fn rocket() -> _ { - let figment = Figment::from(rocket::Config::default()) - .merge(Serialized::defaults(Config::default())) - .merge(Toml::file("App.toml").nested()) - .merge(Env::prefixed("APP_").global()) - .select(Profile::from_env_or("APP_PROFILE", "default")); - rocket::custom(figment).mount("/", routes![index]) -} \ No newline at end of file + rocket::build().mount("/", routes![index]) +}