summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAdam T. Carpenter <atc@53hor.net>2021-02-21 22:03:59 -0500
committerAdam T. Carpenter <atc@53hor.net>2021-02-21 22:03:59 -0500
commite58403f3b9c4c8686537c4716a6ed3f65ca48370 (patch)
tree80913283f7146d1f5a89121f40a39e7b025c6dc2 /src
parent9100d5b1f883e5762741ebac08b170ecf14811cd (diff)
downloadtwinh-e58403f3b9c4c8686537c4716a6ed3f65ca48370.tar.xz
twinh-e58403f3b9c4c8686537c4716a6ed3f65ca48370.zip
init upload
Diffstat (limited to 'src')
-rw-r--r--src/main.rs39
-rw-r--r--src/templates/index.html10
2 files changed, 49 insertions, 0 deletions
diff --git a/src/main.rs b/src/main.rs
new file mode 100644
index 0000000..9d4a4f4
--- /dev/null
+++ b/src/main.rs
@@ -0,0 +1,39 @@
+use hyper::service::{make_service_fn, service_fn};
+use hyper::{Body, Request, Response, Server};
+use std::convert::Infallible;
+use std::net::SocketAddr;
+
+#[tokio::main]
+async fn main() {
+ // We'll bind to 127.0.0.1:3000
+ let addr = SocketAddr::from(([127, 0, 0, 1], 3000));
+
+ // A `Service` is needed for every connection, so this
+ // creates one from our `hello_world` function.
+ let make_svc = make_service_fn(|_conn| async {
+ // service_fn converts our function into a `Service`
+ Ok::<_, Infallible>(service_fn(hello_world))
+ });
+
+ // And construct the `Server` like normal...
+ let server = Server::bind(&addr).serve(make_svc);
+
+ // And now add a graceful shutdown signal...
+ let graceful = server.with_graceful_shutdown(shutdown_signal());
+
+ // Run this server for... forever!
+ if let Err(e) = graceful.await {
+ eprintln!("server error: {}", e);
+ }
+}
+
+async fn hello_world(_req: Request<Body>) -> Result<Response<Body>, Infallible> {
+ Ok(Response::new("Hello, World".into()))
+}
+
+async fn shutdown_signal() {
+ // Wait for the CTRL+C signal
+ tokio::signal::ctrl_c()
+ .await
+ .expect("failed to install CTRL+C signal handler");
+}
diff --git a/src/templates/index.html b/src/templates/index.html
new file mode 100644
index 0000000..7b6070c
--- /dev/null
+++ b/src/templates/index.html
@@ -0,0 +1,10 @@
+<!DOCTYPE html>
+<html>
+ <body>
+ <ul>
+ <li>Essex</li>
+ <li>Hudson</li>
+ <li>Terraplane</li>
+ </ul>
+ </body>
+</html>