adds cors to test in dev environment
This commit is contained in:
@@ -13,6 +13,7 @@ env_logger = "*"
|
||||
futures = "0.1"
|
||||
diesel = "*"
|
||||
serde = "*"
|
||||
actix-cors = "0.1.0"
|
||||
|
||||
[workspace]
|
||||
members = [
|
||||
|
||||
@@ -115,15 +115,17 @@ impl<'q> AsPlayer<'q> {
|
||||
/// Adds the value in gold to the player's wealth.
|
||||
///
|
||||
/// Value can be negative to substract wealth.
|
||||
pub fn update_wealth(self, value: f32) -> ActionResult {
|
||||
pub fn update_wealth(self, value_in_gp: f32) -> ActionResult {
|
||||
use schema::players::dsl::*;
|
||||
let current_wealth = players.find(self.id)
|
||||
let current_wealth = players
|
||||
.find(self.id)
|
||||
.select((cp, sp, gp, pp))
|
||||
.first::<models::WealthUpdate>(self.conn)?;
|
||||
// TODO: improve this
|
||||
// should be move inside a WealthUpdate method
|
||||
let update =
|
||||
models::WealthUpdate::from_gp(current_wealth.to_gp() + value);
|
||||
let update = models::WealthUpdate::from_gp(
|
||||
current_wealth.to_gp() + value_in_gp
|
||||
);
|
||||
diesel::update(players)
|
||||
.filter(id.eq(self.id))
|
||||
.set(&update)
|
||||
|
||||
@@ -7,7 +7,9 @@ const PLAYER_LIST = [
|
||||
];
|
||||
|
||||
const fetchPlayerList = function () {
|
||||
|
||||
fetch("http://localhost:8088/players")
|
||||
.then(r => r.json())
|
||||
.then(r => console.log(r));
|
||||
};
|
||||
|
||||
const fetchRequests = function () {
|
||||
@@ -25,6 +27,7 @@ export const AppStorage = {
|
||||
// Initiate the state
|
||||
initStorage (playerId) {
|
||||
if (this.debug) console.log('Initiate with player : ', playerId)
|
||||
fetchPlayerList();
|
||||
this.state.player_id = playerId;
|
||||
for (var idx in PLAYER_LIST) {
|
||||
var player = PLAYER_LIST[idx];
|
||||
|
||||
@@ -6,6 +6,7 @@ extern crate lootalot_db;
|
||||
mod server;
|
||||
|
||||
fn main() {
|
||||
std::env::set_var("RUST_LOG", "actix_web=info");
|
||||
env_logger::init();
|
||||
dotenv::dotenv().ok();
|
||||
// TODO: Build a cli app with complete support of DbApi
|
||||
|
||||
@@ -2,6 +2,7 @@ use std::env;
|
||||
use futures::Future;
|
||||
use actix_files as fs;
|
||||
use actix_web::{web, App, HttpServer, HttpResponse, Error};
|
||||
use actix_cors::Cors;
|
||||
use lootalot_db::{Pool, DbApi, QueryResult};
|
||||
|
||||
type AppPool = web::Data<Pool>;
|
||||
@@ -56,6 +57,12 @@ pub(crate) fn serve() -> std::io::Result<()> {
|
||||
HttpServer::new(move || {
|
||||
App::new()
|
||||
.data(pool.clone())
|
||||
.wrap(
|
||||
Cors::new()
|
||||
.allowed_origin("http://localhost:8080")
|
||||
.allowed_methods(vec!["GET", "POST"])
|
||||
.max_age(3600)
|
||||
)
|
||||
.route(
|
||||
"/players",
|
||||
web::get().to_async(move |pool: AppPool| {
|
||||
|
||||
Reference in New Issue
Block a user