feat(server): add basic HTTP server implementation

This commit is contained in:
orhun 2021-07-20 01:35:52 +03:00
parent 2d3151292d
commit df0d22dcb3
No known key found for this signature in database
GPG Key ID: F83424824B3E4B90
3 changed files with 1854 additions and 2 deletions

1827
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -6,6 +6,9 @@ description = "Orhun's obscure pastebin server"
authors = ["Orhun Parmaksız <orhunparmaksiz@gmail.com>"]
[dependencies]
actix-web = "3.3.2"
env_logger = "0.9.0"
log = "0.4.14"
[profile.dev]
opt-level = 0

View File

@ -1,3 +1,25 @@
fn main() {
println!("Hello, world!");
#[macro_use] extern crate log;
use actix_web::middleware::Logger;
use actix_web::{web, App, HttpResponse, HttpServer, Responder};
async fn index() -> impl Responder {
HttpResponse::Ok().body("Hello world!")
}
fn config(cfg: &mut web::ServiceConfig) {
cfg.service(
web::resource("/")
.route(web::get().to(index))
.route(web::head().to(|| HttpResponse::MethodNotAllowed())),
);
}
#[actix_web::main]
async fn main() -> std::io::Result<()> {
env_logger::init_from_env(env_logger::Env::new().default_filter_or("info"));
HttpServer::new(|| App::new().wrap(Logger::default()).configure(config))
.bind("127.0.0.1:8000")?
.workers(4)
.run()
.await
}