mirror of
https://codeberg.org/JasterV/chat-rooms-actix.git
synced 2026-04-26 18:10:04 +00:00
first commit
This commit is contained in:
commit
392adc8c56
14 changed files with 1942 additions and 0 deletions
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
|
|
@ -0,0 +1 @@
|
|||
/target
|
||||
1868
Cargo.lock
generated
Normal file
1868
Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load diff
15
Cargo.toml
Normal file
15
Cargo.toml
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
[package]
|
||||
name = "actix-messaging"
|
||||
version = "0.1.0"
|
||||
authors = ["Víctor Martínez <victorcoder2@gmail.com>"]
|
||||
edition = "2018"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
[lib]
|
||||
name = "lib"
|
||||
path = "src/lib.rs"
|
||||
|
||||
[dependencies]
|
||||
actix = "0.10.0"
|
||||
actix-web = "3"
|
||||
actix-web-actors = "3.0.0"
|
||||
0
README.md
Normal file
0
README.md
Normal file
0
src/actors/chat_server.rs
Normal file
0
src/actors/chat_server.rs
Normal file
0
src/actors/mod.rs
Normal file
0
src/actors/mod.rs
Normal file
12
src/bin/chat_app.rs
Normal file
12
src/bin/chat_app.rs
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
use actix_web::{App, HttpServer};
|
||||
use lib::server::{app_data, routes};
|
||||
|
||||
#[actix_web::main]
|
||||
async fn main() -> std::io::Result<()> {
|
||||
HttpServer::new(|| {
|
||||
return App::new().configure(app_data).configure(routes);
|
||||
})
|
||||
.bind("127.0.0.1:8080")?
|
||||
.run()
|
||||
.await
|
||||
}
|
||||
4
src/lib.rs
Normal file
4
src/lib.rs
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
pub mod routes;
|
||||
pub mod models;
|
||||
pub mod server;
|
||||
pub mod actors;
|
||||
1
src/models/mod.rs
Normal file
1
src/models/mod.rs
Normal file
|
|
@ -0,0 +1 @@
|
|||
pub mod user;
|
||||
0
src/models/user.rs
Normal file
0
src/models/user.rs
Normal file
23
src/routes/mod.rs
Normal file
23
src/routes/mod.rs
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
pub mod user;
|
||||
pub mod ws;
|
||||
|
||||
use crate::server::AppState;
|
||||
use actix_web::{get, post, web, web::Data, HttpResponse, Responder};
|
||||
|
||||
#[get("/")]
|
||||
pub async fn hello(app: Data<AppState>) -> impl Responder {
|
||||
let app_name = &app.app_name;
|
||||
println!("App name: {}", app_name);
|
||||
HttpResponse::Ok().body("Hello world!")
|
||||
}
|
||||
|
||||
#[post("/echo")]
|
||||
pub async fn echo(req_body: String) -> impl Responder {
|
||||
HttpResponse::Ok().body(req_body)
|
||||
}
|
||||
|
||||
pub async fn manual_hello() -> impl Responder {
|
||||
HttpResponse::Ok().body("Hey there!")
|
||||
}
|
||||
|
||||
|
||||
0
src/routes/user.rs
Normal file
0
src/routes/user.rs
Normal file
0
src/routes/ws.rs
Normal file
0
src/routes/ws.rs
Normal file
18
src/server.rs
Normal file
18
src/server.rs
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
use crate::routes::{echo, hello, manual_hello};
|
||||
use actix_web::web;
|
||||
|
||||
pub struct AppState {
|
||||
pub app_name: String,
|
||||
}
|
||||
|
||||
pub fn app_data(cfg: &mut web::ServiceConfig) {
|
||||
cfg.data(AppState {
|
||||
app_name: String::from("Testing!"),
|
||||
});
|
||||
}
|
||||
|
||||
pub fn routes(cfg: &mut web::ServiceConfig) {
|
||||
cfg.service(hello)
|
||||
.service(echo)
|
||||
.route("/hey", web::get().to(manual_hello));
|
||||
}
|
||||
Loading…
Reference in a new issue