about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--.gitignore2
-rw-r--r--Cargo.toml18
-rw-r--r--client/index.html28
-rw-r--r--client/main.css99
-rw-r--r--client/main.js13
-rw-r--r--src/main.rs59
-rw-r--r--src/schema.rs0
-rw-r--r--src/types.rs0
8 files changed, 219 insertions, 0 deletions
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 <einebeere@gmail.com>"]
+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 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+    <meta charset="UTF-8">
+    <title>Shor</title>
+    <link rel="stylesheet" href="main.css">
+    <script src="main.js"></script>
+</head>
+<body>
+<div class="active">
+    <div class="title">
+        <a><b>sho.rest</b><br></a>
+        <a>Made with ❤ by <b>Mel</b></a>
+    </div>
+    <form class="form-inline" onsubmit="onFormSubmit(); return false;">
+        <div class="input-group" id="form-group">
+            <div class="input-container">
+                <a class="input-field-text">https://</a>
+                <input oninput="inputUpdate()" pattern="(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?" class="input-field" id="url" required>
+            </div>
+            <div class="btn-container">
+                <input type="submit" value="→" class="btn">
+            </div>
+        </div>
+    </form>
+</div>
+</body>
+</html>
\ 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<UserData>) -> 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
--- /dev/null
+++ b/src/schema.rs
diff --git a/src/types.rs b/src/types.rs
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/src/types.rs