Compare commits
2 Commits
5b1f437773
...
df42a755f7
Author | SHA1 | Date | |
---|---|---|---|
df42a755f7 | |||
5c78958ec7 |
@ -4,7 +4,8 @@ Example `config.extension` file to be created in `etc` sub-directory of working
|
||||
|
||||
```yaml
|
||||
---
|
||||
port: 8356
|
||||
bind: <Optional, bind/interface to listen requests on. By default localhost only>
|
||||
port: <Optional port, start service on 7777 by default>
|
||||
apps:
|
||||
example-website.tld/optional_domain_path:
|
||||
AUTH_TOKEN: <a super secret token sent in request>
|
||||
|
24
src/main.rs
24
src/main.rs
@ -1,7 +1,7 @@
|
||||
/*
|
||||
Run as `RUST_LOG=debug ./deployment-api-rs`
|
||||
*/
|
||||
use actix_web::{App, HttpRequest, HttpResponse, HttpServer, Responder, Result, post, web};
|
||||
use actix_web::{App, HttpRequest, HttpResponse, HttpServer, Responder, Result, get, post, web};
|
||||
use config::Config;
|
||||
use log::{debug, error, info, warn};
|
||||
use serde::Deserialize;
|
||||
@ -56,10 +56,23 @@ impl AppConfig {
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
struct Settings {
|
||||
#[serde(default = "Settings::default_bind_localhost")]
|
||||
bind: String,
|
||||
#[serde(default = "Settings::default_port")]
|
||||
port: u16,
|
||||
apps: HashMap<String, AppConfig>,
|
||||
}
|
||||
|
||||
impl Settings {
|
||||
fn default_port() -> u16 {
|
||||
7777
|
||||
}
|
||||
|
||||
fn default_bind_localhost() -> String {
|
||||
String::from("127.0.0.1")
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
struct QueryParams {
|
||||
auth_token: String,
|
||||
@ -127,6 +140,11 @@ fn release_deployment_lock(request_id: &str, app_name: &str) {
|
||||
}
|
||||
}
|
||||
|
||||
#[get("/ping")]
|
||||
async fn ping() -> impl Responder {
|
||||
"\\\\m//"
|
||||
}
|
||||
|
||||
#[post("/deploy")]
|
||||
async fn deploy(
|
||||
request: HttpRequest,
|
||||
@ -341,8 +359,8 @@ async fn main() -> std::io::Result<()> {
|
||||
APPS_CONFIG.get_or_init(|| settings.apps);
|
||||
APPS_DEPLOYMENT_LOCK.get_or_init(|| RwLock::new(HashSet::new()));
|
||||
|
||||
HttpServer::new(|| App::new().service(deploy))
|
||||
.bind(("127.0.0.1", settings.port))?
|
||||
HttpServer::new(|| App::new().service(deploy).service(ping))
|
||||
.bind((settings.bind.as_str(), settings.port))?
|
||||
.run()
|
||||
.await
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user