Browse Source

Upgrade actix-web and other dependencies; Update version to 0.2.1

admin-impl 0.2.1
Kevin Hoerr 1 year ago
parent
commit
87a703ae22
4 changed files with 31 additions and 35 deletions
  1. +1
    -0
      .env.sample
  2. +6
    -6
      Cargo.toml
  3. +19
    -22
      src/main.rs
  4. +5
    -7
      src/routes/mod.rs

+ 1
- 0
.env.sample View File

@ -1,2 +1,3 @@
DATABASE_URL=postgres://username:password@localhost/august_offensive
BIND_ADDRESS=127.0.0.1:8080
RUST_LOG=info,actix_server=warn

+ 6
- 6
Cargo.toml View File

@ -1,6 +1,6 @@
[package]
name = "august-offensive"
version = "0.2.0"
version = "0.2.1"
authors = ["Kevin J Hoerr <kjhoerr@submelon.tech>"]
description = "Turn-based strategy game as a web service"
license = "ISC"
@ -13,12 +13,12 @@ path = "src/main.rs"
[dependencies]
dotenv = "0.10"
env_logger = "0.5"
failure = "^0.1"
log = "0.4.0"
env_logger = "0.6.2"
diesel = { version = "1.3.0", features = ["postgres"] }
diesel = { version = "1.4.2", features = ["postgres"] }
actix = "0.7"
actix-web = "^0.7"
actix-rt = "0.2.4"
actix-web = "1.0.5"
serde = "1.0"
serde_derive = "1.0"

+ 19
- 22
src/main.rs View File

@ -1,11 +1,9 @@
// specify recurse depth for error_chain
#![recursion_limit = "1024"]
extern crate actix;
extern crate actix_rt;
extern crate actix_web;
extern crate dotenv;
#[macro_use]
extern crate log;
extern crate env_logger;
extern crate failure;
#[macro_use]
extern crate diesel;
extern crate serde;
@ -15,13 +13,13 @@ extern crate serde_derive;
pub mod routes;
pub mod schema;
use actix_web::{middleware, server, App};
use actix_web::{middleware, web, App, HttpServer};
use diesel::pg::PgConnection;
use diesel::prelude::*;
use dotenv::dotenv;
use failure::Error;
use routes::*;
use std::env;
use std::io::Error;
fn main() {
if let Err(ref e) = run() {
@ -36,23 +34,22 @@ fn run() -> Result<(), Error> {
let db_url = env::var("DATABASE_URL").expect("DATABASE_URL must be set");
let bind_address = env::var("BIND_ADDRESS").expect("BIND_ADDRESS must be set");
env::set_var("RUST_LOG", "actix_web=info");
env_logger::init();
let sys = actix::System::new("august-offensive");
let sys = actix_rt::System::new("august-offensive");
PgConnection::establish(&db_url).expect(&format!("Error connecting to {}", db_url));
server::new(|| {
App::new()
.middleware(middleware::Logger::default())
.prefix("/api")
.handler("/callback", callback)
.default_resource(|r| r.f(not_understood))
}).bind(&bind_address)
.unwrap()
.start();
println!("Started http server: {}", bind_address);
let _ = sys.run();
Ok(())
HttpServer::new(|| {
App::new().wrap(middleware::Logger::default()).service(
web::scope("/api")
.service(web::scope("/callback").default_service(web::route().to(callback)))
.default_service(web::route().to(not_understood)),
)
})
.bind(&bind_address)?
.start();
info!("Started http server: {}", bind_address);
sys.run()
}

+ 5
- 7
src/routes/mod.rs View File

@ -1,5 +1,5 @@
use actix_web::{HttpRequest, Json, Result};
use std::ops::Deref;
use actix_web::{web::Json, web::Query, HttpRequest, Result};
use std::collections::HashMap;
pub mod messages;
use messages::*;
@ -7,7 +7,7 @@ use messages::*;
type JsonMessage<U> = Result<Json<OutgoingMsg<U>>>;
// Sends a default response message when requested an undefined resource.
pub fn not_understood(req: &HttpRequest) -> JsonMessage<NotUnderstood> {
pub fn not_understood(req: HttpRequest) -> JsonMessage<NotUnderstood> {
let message = NotUnderstood {
path: destruct_path(req.path()),
};
@ -16,16 +16,14 @@ pub fn not_understood(req: &HttpRequest) -> JsonMessage<NotUnderstood> {
}
// Sends Callback message with information from HttpRequest.
pub fn callback(req: &HttpRequest) -> JsonMessage<Callback> {
pub fn callback(req: HttpRequest, query: Query<HashMap<String, String>>) -> JsonMessage<Callback> {
let path = req.path();
let method = req.method().as_str();
let query_ref = req.query();
let request = query_ref.deref().clone();
let callback = Callback {
path: destruct_path(path),
request: String::from(method),
content: request,
content: query.into_inner(),
};
Ok(Json(callback.as_outgoing()))


Loading…
Cancel
Save