Skip to content

Commit

Permalink
Add Rocket.toml and update Spacefile and main.rs
Browse files Browse the repository at this point in the history
  • Loading branch information
rabilrbl committed Feb 7, 2024
1 parent b263edd commit 6e51bd4
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 28 deletions.
16 changes: 16 additions & 0 deletions Rocket.toml
Original file line number Diff line number Diff line change
@@ -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="
3 changes: 2 additions & 1 deletion Spacefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
- server
- Rocket.toml
31 changes: 4 additions & 27 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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])
}
rocket::build().mount("/", routes![index])
}

0 comments on commit 6e51bd4

Please sign in to comment.