adds server to serve the static files, fixes db tables
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -5,4 +5,5 @@ node_modules
|
||||
fontawesome
|
||||
|
||||
Cargo.lock
|
||||
**/*.sqlite3
|
||||
|
||||
|
||||
@@ -4,6 +4,11 @@ version = "0.1.0"
|
||||
authors = ["Artus <artus@landoftheunicorn.ovh>"]
|
||||
edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
actix-web = "0.7"
|
||||
lootalot-db = { version = "0.1", path = "./lootalot_db" }
|
||||
dotenv = "*"
|
||||
|
||||
[workspace]
|
||||
members = [
|
||||
"lootalot_db"
|
||||
|
||||
Binary file not shown.
@@ -1,5 +1,5 @@
|
||||
CREATE TABLE items (
|
||||
id INTEGER PRIMARY KEY,
|
||||
id INTEGER PRIMARY KEY NOT NULL,
|
||||
name VARCHAR NOT NULL,
|
||||
base_price INTEGER NOT NULL
|
||||
);
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
CREATE TABLE players (
|
||||
id INTEGER PRIMARY KEY,
|
||||
id INTEGER PRIMARY KEY NOT NULL,
|
||||
name VARCHAR NOT NULL,
|
||||
debt INTEGER DEFAULT 0, -- debt to the group in copper pieces
|
||||
cp INTEGER DEFAULT 0,
|
||||
sp INTEGER DEFAULT 0,
|
||||
gp INTEGER DEFAULT 0,
|
||||
pp INTEGER DEFAULT 0
|
||||
debt INTEGER DEFAULT 0 NOT NULL, -- debt to the group in copper pieces
|
||||
cp INTEGER DEFAULT 0 NOT NULL,
|
||||
sp INTEGER DEFAULT 0 NOT NULL,
|
||||
gp INTEGER DEFAULT 0 NOT NULL,
|
||||
pp INTEGER DEFAULT 0 NOT NULL
|
||||
);
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
CREATE TABLE looted (
|
||||
id INTEGER PRIMARY KEY,
|
||||
id INTEGER PRIMARY KEY NOT NULL,
|
||||
player_id INTEGER NOT NULL,
|
||||
item_id INTEGER NOT NULL,
|
||||
acquired_date DATE DEFAULT NOW,
|
||||
acquired_date DATE NOT NULL,
|
||||
FOREIGN KEY (player_id) REFERENCES players(id),
|
||||
FOREIGN KEY (item_id) REFERENCES items(id)
|
||||
);
|
||||
|
||||
@@ -23,7 +23,6 @@ pub fn list_players() -> Vec<models::Player> {
|
||||
players
|
||||
.load::<models::Player>(&conn)
|
||||
.expect("Error loading players")
|
||||
.collect()
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
table! {
|
||||
items (id) {
|
||||
id -> Nullable<Integer>,
|
||||
id -> Integer,
|
||||
name -> Text,
|
||||
base_price -> Integer,
|
||||
}
|
||||
@@ -8,22 +8,22 @@ table! {
|
||||
|
||||
table! {
|
||||
looted (id) {
|
||||
id -> Nullable<Integer>,
|
||||
id -> Integer,
|
||||
player_id -> Integer,
|
||||
item_id -> Integer,
|
||||
acquired_date -> Nullable<Date>,
|
||||
acquired_date -> Date,
|
||||
}
|
||||
}
|
||||
|
||||
table! {
|
||||
players (id) {
|
||||
id -> Nullable<Integer>,
|
||||
id -> Integer,
|
||||
name -> Text,
|
||||
debt -> Nullable<Integer>,
|
||||
cp -> Nullable<Integer>,
|
||||
sp -> Nullable<Integer>,
|
||||
gp -> Nullable<Integer>,
|
||||
pp -> Nullable<Integer>,
|
||||
debt -> Integer,
|
||||
cp -> Integer,
|
||||
sp -> Integer,
|
||||
gp -> Integer,
|
||||
pp -> Integer,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
20
src/main.rs
20
src/main.rs
@@ -1,5 +1,25 @@
|
||||
extern crate lootalot_db;
|
||||
extern crate actix_web;
|
||||
extern crate dotenv;
|
||||
|
||||
use std::env;
|
||||
use std::cell::RefCell;
|
||||
use std::rc::Rc;
|
||||
use actix_web::{server, App, Result, HttpRequest, fs };
|
||||
|
||||
|
||||
fn main() {
|
||||
println!("Hello, world!");
|
||||
|
||||
dotenv::dotenv().ok();
|
||||
|
||||
let www_root: String = env::var("WWW_ROOT").expect("WWW_ROOT must be set");
|
||||
println!("serving files from: {}", &www_root);
|
||||
server::new(move || {
|
||||
App::new()
|
||||
.handler("/", fs::StaticFiles::new(www_root.clone()).unwrap().index_file("index.html"))
|
||||
})
|
||||
.bind("127.0.0.1:8088")
|
||||
.unwrap()
|
||||
.run();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user