-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from Basicprogrammer10/1.0.0
🥧 Version 1.0.0
- Loading branch information
Showing
20 changed files
with
462 additions
and
226 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
use afire::{Method, Response, Server}; | ||
|
||
// Create a new basic server like in example 01 | ||
// However, we want to use a thread pool to handle the requests | ||
// This is incredibly simple in afire | ||
|
||
// In production, you would probably want to use a reverse proxy like nginx | ||
// or something similar to split the load across multiple servers | ||
// But just a thread pool is a good way to get started | ||
|
||
fn main() { | ||
// Create a new Server instance on localhost port 8080 | ||
let mut server: Server = Server::new("localhost", 8080); | ||
|
||
// Define a handler for GET "/" | ||
server.route(Method::GET, "/", |_req| { | ||
Response::new() | ||
.status(200) | ||
.text("Hello from ThreadPool!") | ||
.header("Content-Type", "text/plain") | ||
}); | ||
|
||
println!("[13] Listening on http://{}:{}", server.ip, server.port); | ||
|
||
// Start the server with 8 threads | ||
// This will block the current thread | ||
server.start_threaded(8); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
use std::sync::atomic::{AtomicU32, Ordering}; | ||
|
||
use afire::prelude::*; | ||
|
||
struct Log(AtomicU32); | ||
|
||
impl Middleware for Log { | ||
fn pre(&self, _req: Request) -> MiddleRequest { | ||
let i = self.0.fetch_add(1, Ordering::Release); | ||
println!("{}", i); | ||
|
||
std::thread::sleep(std::time::Duration::from_secs(10)); | ||
|
||
MiddleRequest::Continue | ||
} | ||
|
||
fn end(&self, _req: Request, _res: Response) { | ||
std::thread::sleep(std::time::Duration::from_secs(10)); | ||
} | ||
} | ||
|
||
impl Log { | ||
fn new() -> Self { | ||
Self(AtomicU32::new(0)) | ||
} | ||
} | ||
|
||
fn main() { | ||
let mut server: Server = Server::new("localhost", 8818); | ||
|
||
Log::new().attach(&mut server); | ||
|
||
server.route(Method::GET, "/", |_req| { | ||
Response::new() | ||
.status(200) | ||
.reason("OK!") | ||
.text("Hi :P") | ||
.header("Content-Type", "text/plain") | ||
}); | ||
|
||
server.start_threaded(4).unwrap(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.