From bc42d900d956f11307d14136f8e24d7cd793b012 Mon Sep 17 00:00:00 2001 From: Melonai Date: Thu, 7 May 2020 00:53:08 +0200 Subject: initial structure --- .gitignore | 2 ++ Cargo.toml | 18 ++++++++++ client/index.html | 28 ++++++++++++++++ client/main.css | 99 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ client/main.js | 13 ++++++++ src/main.rs | 59 +++++++++++++++++++++++++++++++++ src/schema.rs | 0 src/types.rs | 0 8 files changed, 219 insertions(+) create mode 100644 .gitignore create mode 100644 Cargo.toml create mode 100644 client/index.html create mode 100644 client/main.css create mode 100644 client/main.js create mode 100644 src/main.rs create mode 100644 src/schema.rs create mode 100644 src/types.rs diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..212de44 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +/target +.DS_Store \ No newline at end of file diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..c345892 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,18 @@ +[package] +name = "actix-web-server" +version = "0.1.0" +authors = ["Melonai "] +edition = "2018" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +actix-web = "2.0" +actix-rt = "1.0" +listenfd = "0.3" +serde = "1.0.106" +serde_json = "1.0.51" +serde_derive = "1.0.106" +json = "0.12.4" +env_logger = "0.7.1" +aes = "0.3.2" diff --git a/client/index.html b/client/index.html new file mode 100644 index 0000000..a8aa831 --- /dev/null +++ b/client/index.html @@ -0,0 +1,28 @@ + + + + + Shor + + + + +
+ +
+
+
+ https:// + +
+
+ +
+
+
+
+ + \ No newline at end of file diff --git a/client/main.css b/client/main.css new file mode 100644 index 0000000..8f84f71 --- /dev/null +++ b/client/main.css @@ -0,0 +1,99 @@ +html * { + font-family: Roboto, sans-serif; + font-size: 18px; +} + +.active { + justify-content: center; + max-width: 100vw; + margin-top: 20%; + padding: 0 50px 0 50px; +} + +.title { + padding-left: 30px; + margin-bottom: 10px; + line-height: 1.42857143; + color: #E0E0E0; +} + +.input-group { + position: relative; + display: table; + border-collapse: separate; + border-color: #E0E0E0; + transition: border-color 1s; +} + +.input-field { + position: relative; + z-index: 2; + margin-bottom: 0; + text-indent: 0; + color: #727272; + background-color: #fff; + background-image: none; + box-sizing: border-box; + border: none; + outline: none; + height: 100%; + width: 100%; +} + +.input-field-text { + margin-left: 30px; + box-sizing: border-box; + color: #E0E0E0; +} + +.input-container { + z-index: 2; + width: 100%; + float: left; + display: flex; + align-items: center; + position: relative; + padding: 0; + border-radius: 100px 0 0 100px; + border: 2px solid; + border-color: inherit; + margin: 0; + box-sizing: border-box; + height: 10vh; +} + +.btn-container { + display: table-cell; + position: relative; + font-size: 0; + white-space: nowrap; + width: 1%; + height: 0; + vertical-align: middle; + border-color: inherit; +} + +.btn { + z-index: 2; + margin-left: -1px; + display: inline-block; + margin-bottom: 0; + font-weight: 400; + text-align: center; + white-space: nowrap; + vertical-align: middle; + -ms-touch-action: manipulation; + touch-action: manipulation; + cursor: pointer; + background-image: none; + padding: 4px 5vw; + height: 10vh; + -webkit-user-select: none; + -moz-user-select: none; + -ms-user-select: none; + user-select: none; + border-radius: 0 100px 100px 0; + border: 2px solid; + border-color: inherit; + border-left: none; +} \ No newline at end of file diff --git a/client/main.js b/client/main.js new file mode 100644 index 0000000..652776a --- /dev/null +++ b/client/main.js @@ -0,0 +1,13 @@ +function onFormSubmit() { + return false; +} + +function inputUpdate() { + const pattern = /^(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?&/; + const userInput = document.getElementById('url').value; + if (pattern.test(userInput)) { + document.getElementById('form-group').style.borderColor = '#E0E0E0'; + } else { + document.getElementById('form-group').style.borderColor = '#FFBCBC'; + } +} \ No newline at end of file diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..8e5e1fa --- /dev/null +++ b/src/main.rs @@ -0,0 +1,59 @@ +extern crate actix_web; +extern crate env_logger; +#[macro_use] extern crate serde_derive; + +use actix_web::{middleware, web, HttpServer, App, HttpResponse, HttpRequest}; +use listenfd::ListenFd; +use actix_web::web::Json; + +#[derive(Debug, Deserialize)] +struct UserData { + url: String +} + +#[derive(Debug, Serialize)] +struct UserResponse { + hash: String, + key: String +} + +async fn root() -> HttpResponse { + HttpResponse::Ok().body("Please make a POST request to / with the URL you want to shorten!") +} + +async fn shorten(req: HttpRequest, params: Json) -> HttpResponse { + //println!("{:?}", req.head()); + println!("{:?}", params.url); + HttpResponse::Ok().body("Right back at you!") +} + +async fn redirect() -> HttpResponse { + HttpResponse::TemporaryRedirect().header("Location", "http://google.com/").finish() +} + +#[actix_rt::main] +async fn main() -> std::io::Result<()> { + let mut lfd = ListenFd::from_env(); + std::env::set_var("RUST_LOG", "actix_web=info"); + env_logger::init(); + let mut server = HttpServer::new(|| { + App::new() + .wrap(middleware::Logger::default()) + .service( + web::resource("/") + .route(web::get().to(root)) + .route(web::post().to(shorten)) + ) + .service( + web::resource("/{hash}/{key}") + .route(web::get().to(redirect)) + ) + }); + server = if let Some(l) = lfd.take_tcp_listener(0).unwrap() { + server.listen(l)? + } else { + server.bind("localhost:3000")? + }; + + server.run().await +} diff --git a/src/schema.rs b/src/schema.rs new file mode 100644 index 0000000..e69de29 diff --git a/src/types.rs b/src/types.rs new file mode 100644 index 0000000..e69de29 -- cgit 1.4.1