feat(library): basic library structure completed
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
# TODO
|
||||
- [ ] Manage requests
|
||||
- [ ] Router
|
||||
- [x] Manage requests
|
||||
- [x] Router
|
||||
- [NOT NEEDED] HTTP code mapper : not needed because a code will be directly translated on the client (browser / postman)
|
||||
- [ ] JS / CSS data
|
||||
- [ ] Media manager
|
||||
@@ -8,6 +8,8 @@
|
||||
- [ ] File management
|
||||
- [ ] Auto-cleanup
|
||||
- [ ] Transversal utility
|
||||
- [ ] Let programmer set the default not found response
|
||||
- [ ] Allow middleware
|
||||
|
||||
## Improvements
|
||||
|
||||
|
||||
@@ -5,5 +5,5 @@ mod types;
|
||||
|
||||
use generators::*;
|
||||
use parsers::*;
|
||||
use server::*;
|
||||
use types::*;
|
||||
pub use server::*;
|
||||
pub use types::*;
|
||||
|
||||
@@ -9,7 +9,11 @@ impl HttpApp {
|
||||
self.routes.first() // TODO: search the real one
|
||||
}
|
||||
|
||||
fn process_petition(&self, stream: &mut TcpStream) -> ProcessedResponse {
|
||||
pub fn add_route(&mut self, route: HttpAppRoute) {
|
||||
self.routes.push(route);
|
||||
}
|
||||
|
||||
pub fn process_petition(&self, stream: &mut TcpStream) -> ProcessedResponse {
|
||||
let mut buffer = [0; 1024]; // TODO: manage this size
|
||||
let _amount = stream.read(&mut buffer);
|
||||
let petition = String::from_utf8_lossy(&buffer[..]);
|
||||
@@ -19,7 +23,8 @@ impl HttpApp {
|
||||
Ok(petition_parsed) => {
|
||||
let response_status = "200 OK";
|
||||
|
||||
let mut response_content = fs::read_to_string("./routes/index.html").unwrap();
|
||||
// let mut response_content = fs::read_to_string("./routes/index.html").unwrap();
|
||||
let mut response_content = "".to_string();
|
||||
|
||||
if let Some(route) = self.get_route(petition_parsed.request.query.path) {
|
||||
response_content = (route.action)(petition_parsed);
|
||||
@@ -50,8 +55,8 @@ impl HttpApp {
|
||||
}
|
||||
}
|
||||
|
||||
fn start(&self) {
|
||||
let addr = SocketAddr::from(([127, 0, 0, 1], 80));
|
||||
pub fn start(&self) {
|
||||
let addr = SocketAddr::from(([127, 0, 0, 1], self.config.port));
|
||||
|
||||
let listener = TcpListener::bind(addr).unwrap();
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ use std::collections::HashMap;
|
||||
* App types
|
||||
* */
|
||||
pub struct HttpAppConfig {
|
||||
port: u8,
|
||||
pub port: u16,
|
||||
}
|
||||
|
||||
pub type HttpAppRouteFunction = Box<fn(HttpRequest) -> String>;
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
mod http;
|
||||
|
||||
pub use http::*;
|
||||
|
||||
pub fn add(left: u64, right: u64) -> u64 {
|
||||
left + right
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user