added request handling to a separate module

This commit is contained in:
Gonçalo Valério 2019-03-24 20:17:55 +00:00
parent f14941208a
commit ecb8f4eab7
2 changed files with 8 additions and 5 deletions

5
src/controllers.rs Normal file
View File

@ -0,0 +1,5 @@
use actix_web::{HttpRequest, Responder};
pub fn index(_req: &HttpRequest) -> impl Responder {
"Hello world!"
}

View File

@ -1,11 +1,9 @@
extern crate actix_web;
extern crate clap;
use clap::{Arg};
use actix_web::{server, App, HttpRequest, Responder};
use actix_web::{server, App};
fn index(_req: &HttpRequest) -> impl Responder {
"Hello world!"
}
mod controllers;
fn main() {
println!("[rustyhub] Launching hub");
@ -32,7 +30,7 @@ fn main() {
}
println!("[rustyhub] Starting server");
server::new(|| App::new().resource("/", |r| r.f(index)))
server::new(|| App::new().resource("/", |r| r.f(controllers::index)))
.bind(format!("{}:{}", address, port))
.unwrap()
.run();