updates for prod env
This commit is contained in:
13
src/api.rs
13
src/api.rs
@@ -16,6 +16,7 @@ pub struct BuySellParams {
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
pub struct NewGroupLoot {
|
||||
source_name: String,
|
||||
// claims_limit_date: String
|
||||
pub items: ItemList,
|
||||
}
|
||||
|
||||
@@ -80,8 +81,6 @@ pub enum ApiActions {
|
||||
BuyItems(i32, BuySellParams),
|
||||
SellItems(i32, BuySellParams),
|
||||
ClaimItems(i32, IdList),
|
||||
ClaimItem(i32, i32),
|
||||
UnclaimItem(i32, i32),
|
||||
UndoLastAction(i32),
|
||||
// Group level
|
||||
AddLoot(NewGroupLoot),
|
||||
@@ -235,16 +234,6 @@ pub fn execute(
|
||||
Ok(Some((id, "Vente d'objets")))
|
||||
})?
|
||||
}
|
||||
ApiActions::ClaimItem(id, item) => {
|
||||
response.push_update(db::Claims(conn).add(id, item)?);
|
||||
response.notify("Pour moi !".to_string());
|
||||
None
|
||||
}
|
||||
ApiActions::UnclaimItem(id, item) => {
|
||||
response.push_update(db::Claims(conn).remove(id, item)?);
|
||||
response.notify("Bof! Finalement non.".to_string());
|
||||
None
|
||||
}
|
||||
ApiActions::ClaimItems(id, items) => {
|
||||
conn.transaction(|| -> Result<Option<(i32, &str)>, diesel::result::Error> {
|
||||
let current_claims: HashSet<i32> = db::Claims(conn)
|
||||
|
||||
@@ -136,16 +136,6 @@ fn configure_api(config: &mut web::ServiceConfig) {
|
||||
db_call(pool, Q::ClaimItems(*player, data.into_inner()))
|
||||
},
|
||||
))
|
||||
.route(web::put().to_async(
|
||||
|pool, (player, data): (PlayerId, ItemId)| {
|
||||
db_call(pool, Q::ClaimItem(*player, *data))
|
||||
},
|
||||
))
|
||||
.route(web::delete().to_async(
|
||||
|pool, (player, data): (PlayerId, ItemId)| {
|
||||
db_call(pool, Q::UnclaimItem(*player, *data))
|
||||
},
|
||||
)),
|
||||
)
|
||||
.service(
|
||||
web::resource("/wealth")
|
||||
@@ -294,12 +284,11 @@ fn enter_session(id: Identity, pool: AppPool) -> impl Future<Item = HttpResponse
|
||||
}
|
||||
|
||||
pub fn serve() -> std::io::Result<()> {
|
||||
let www_root: String = env::var("WWW_ROOT").expect("WWW_ROOT must be set");
|
||||
let domain: String = env::var("DOMAIN").expect("DOMAIN must be set");
|
||||
let pool = db::create_pool();
|
||||
dbg!(&www_root);
|
||||
println!("Serving Loot-a-lot on {}", domain);
|
||||
|
||||
let key = [0; 32]; // TODO: Use a real key
|
||||
let domain = "http://localhost:8088";
|
||||
|
||||
HttpServer::new(move || {
|
||||
App::new()
|
||||
@@ -307,7 +296,7 @@ pub fn serve() -> std::io::Result<()> {
|
||||
.configure(configure_api)
|
||||
.wrap(
|
||||
Cors::new()
|
||||
.allowed_origin(domain)
|
||||
.allowed_origin(&domain)
|
||||
.allowed_methods(vec!["GET", "POST", "PUT", "DELETE", "OPTIONS"])
|
||||
.max_age(3600),
|
||||
)
|
||||
@@ -321,7 +310,7 @@ pub fn serve() -> std::io::Result<()> {
|
||||
.route("/session", web::get().to_async(enter_session))
|
||||
.route("/login", web::get().to(login))
|
||||
.route("/logout", web::get().to(logout))
|
||||
.service(fs::Files::new("/", www_root.clone()).index_file("index.html"))
|
||||
//.service(fs::Files::new("/", www_root.clone()).index_file("index.html"))
|
||||
})
|
||||
.bind("127.0.0.1:8088")?
|
||||
.run()
|
||||
|
||||
Reference in New Issue
Block a user