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