chore: work on project structure
This commit is contained in:
@@ -7,3 +7,6 @@ edition = "2018"
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
actix-web = "^3.3"
|
||||
env_logger = "^0.8"
|
||||
dotenv = "^0.15"
|
||||
|
||||
31
server/src/main.rs
Normal file
31
server/src/main.rs
Normal file
@@ -0,0 +1,31 @@
|
||||
use actix_web::{get, web, App, HttpServer, Responder};
|
||||
use actix_web::{middleware::Logger, HttpRequest};
|
||||
use dotenv::dotenv;
|
||||
use std::io;
|
||||
use web::Path as WebPath;
|
||||
|
||||
#[actix_web::main]
|
||||
async fn main() -> io::Result<()> {
|
||||
dotenv().ok();
|
||||
env_logger::init();
|
||||
|
||||
HttpServer::new(|| {
|
||||
App::new()
|
||||
.wrap(Logger::default())
|
||||
.service(index)
|
||||
.service(test)
|
||||
})
|
||||
.bind("127.0.0.1:8080")?
|
||||
.run()
|
||||
.await
|
||||
}
|
||||
|
||||
#[get("/{id}/{name}/index.html")]
|
||||
async fn index(WebPath((id, name)): WebPath<(u32, String)>) -> impl Responder {
|
||||
format!("Hello {}! id:{}", name, id)
|
||||
}
|
||||
|
||||
#[get("/test")]
|
||||
async fn test(_req: HttpRequest) -> impl Responder {
|
||||
"This is a Test Response"
|
||||
}
|
||||
Reference in New Issue
Block a user