Browse Source

server begin

pull/25/head
Alexey Velikiy 3 years ago
parent
commit
4c2a3849fe
  1. 1
      server/.gitignore
  2. 45
      server/.vscode/launch.json
  3. 1094
      server/Cargo.lock
  4. 12
      server/Cargo.toml
  5. 33
      server/src/main.rs
  6. 18
      server/src/user_service.rs

1
server/.gitignore vendored

@ -0,0 +1 @@
target/*

45
server/.vscode/launch.json vendored

@ -0,0 +1,45 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "lldb",
"request": "launch",
"name": "Debug executable 'hastic'",
"cargo": {
"args": [
"build",
"--bin=hastic",
"--package=hastic"
],
"filter": {
"name": "hastic",
"kind": "bin"
}
},
"args": [],
"cwd": "${workspaceFolder}"
},
{
"type": "lldb",
"request": "launch",
"name": "Debug unit tests in executable 'hastic'",
"cargo": {
"args": [
"test",
"--no-run",
"--bin=hastic",
"--package=hastic"
],
"filter": {
"name": "hastic",
"kind": "bin"
}
},
"args": [],
"cwd": "${workspaceFolder}"
}
]
}

1094
server/Cargo.lock generated

File diff suppressed because it is too large Load Diff

12
server/Cargo.toml

@ -0,0 +1,12 @@
[package]
name = "hastic"
version = "0.0.1"
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
tokio = { version = "1", features = ["full"] }
warp = "0.3"
parking_lot = "0.11.2"
serde = { version = "1.0", features = ["derive"] }

33
server/src/main.rs

@ -0,0 +1,33 @@
use warp::{Filter, http::Response };
use warp::filters::method::post;
mod user_service;
fn json_body() -> impl Filter<Extract = (user_service::User,), Error = warp::Rejection> + Clone {
// When accepting a body, we want a JSON body
// (and to reject huge payloads)...
warp::body::content_length_limit(1024 * 16).and(warp::body::json())
}
#[tokio::main]
async fn main() {
let routes = warp::any().map(|| {
Response::builder()
.header("Access-Control-Allow-Origin", "*")
.header("Access-Control-Allow-Methods", "POST, GET, OPTIONS, DELETE")
.header("Access-Control-Allow-Headers", "*")
.body("and a custom body")
// "Hello, World!"
});
let hello = warp::path!("api" / "auth" / "signin")
.and(post())
.and(json_body())
.map(|user: user_service::User| {
format!("Hello, {}!", &user.username)
});
warp::serve(routes)
.run(([127, 0, 0, 1], 8000))
.await;
}

18
server/src/user_service.rs

@ -0,0 +1,18 @@
use serde::{ Deserialize, Serialize };
#[derive(Debug, Deserialize, Serialize, Clone)]
pub struct User {
pub username: String,
pub password: String
}
pub struct UserService {
}
impl UserService {
pub fn new() -> UserService {
UserService{}
}
}
Loading…
Cancel
Save