summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSanto Cariotti <santo@dcariotti.me>2021-03-19 20:27:53 +0100
committerGitHub <noreply@github.com>2021-03-19 20:27:53 +0100
commit4249c2e09579d6454e7572111e44c284190a2c8f (patch)
treefc47bb02aa430accce176903af5e36b81179c87a
parent9a791db0c1a8bd08cf51950ed28066adcef84bca (diff)
parent8225cba5ce69a073b54e2eeba7c9d466efa107e3 (diff)
Merge pull request #20 from gico-net/feat/cors
Enable CORS
-rw-r--r--Cargo.lock465
-rw-r--r--Cargo.toml3
-rw-r--r--src/branch/routes.rs26
-rw-r--r--src/commit/models.rs8
-rw-r--r--src/commit/routes.rs20
-rw-r--r--src/email/routes.rs5
-rw-r--r--src/main.rs19
-rw-r--r--src/repository/routes.rs14
8 files changed, 479 insertions, 81 deletions
diff --git a/Cargo.lock b/Cargo.lock
index e035a1b..a36bfdd 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -46,8 +46,41 @@ dependencies = [
"futures",
"http",
"log",
- "trust-dns-proto",
- "trust-dns-resolver",
+ "trust-dns-proto 0.18.0-alpha.2",
+ "trust-dns-resolver 0.18.0-alpha.2",
+]
+
+[[package]]
+name = "actix-connect"
+version = "2.0.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "177837a10863f15ba8d3ae3ec12fac1099099529ed20083a27fdfe247381d0dc"
+dependencies = [
+ "actix-codec 0.3.0",
+ "actix-rt",
+ "actix-service",
+ "actix-utils 2.0.0",
+ "derive_more",
+ "either",
+ "futures-util",
+ "http",
+ "log",
+ "trust-dns-proto 0.19.7",
+ "trust-dns-resolver 0.19.7",
+]
+
+[[package]]
+name = "actix-cors"
+version = "0.5.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "36b133d8026a9f209a9aeeeacd028e7451bcca975f592881b305d37983f303d7"
+dependencies = [
+ "actix-web",
+ "derive_more",
+ "futures-util",
+ "log",
+ "once_cell",
+ "tinyvec",
]
[[package]]
@@ -57,22 +90,19 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c16664cc4fdea8030837ad5a845eb231fb93fc3c5c171edfefb52fad92ce9019"
dependencies = [
"actix-codec 0.2.0",
- "actix-connect",
+ "actix-connect 1.0.2",
"actix-rt",
"actix-service",
"actix-threadpool",
"actix-utils 1.0.6",
"base64 0.11.0",
"bitflags",
- "brotli2",
"bytes 0.5.6",
"chrono",
"copyless",
"derive_more",
"either",
"encoding_rs",
- "failure",
- "flate2",
"futures-channel",
"futures-core",
"futures-util",
@@ -91,10 +121,57 @@ dependencies = [
"regex",
"serde 1.0.124",
"serde_json",
- "serde_urlencoded",
+ "serde_urlencoded 0.6.1",
"sha1",
"slab",
- "time",
+ "time 0.1.44",
+]
+
+[[package]]
+name = "actix-http"
+version = "2.2.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "452299e87817ae5673910e53c243484ca38be3828db819b6011736fc6982e874"
+dependencies = [
+ "actix-codec 0.3.0",
+ "actix-connect 2.0.0",
+ "actix-rt",
+ "actix-service",
+ "actix-threadpool",
+ "actix-utils 2.0.0",
+ "base64 0.13.0",
+ "bitflags",
+ "brotli2",
+ "bytes 0.5.6",
+ "cookie",
+ "copyless",
+ "derive_more",
+ "either",
+ "encoding_rs",
+ "flate2",
+ "futures-channel",
+ "futures-core",
+ "futures-util",
+ "fxhash",
+ "h2",
+ "http",
+ "httparse",
+ "indexmap",
+ "itoa",
+ "language-tags",
+ "lazy_static",
+ "log",
+ "mime",
+ "percent-encoding",
+ "pin-project 1.0.5",
+ "rand",
+ "regex",
+ "serde 1.0.124",
+ "serde_json",
+ "serde_urlencoded 0.7.0",
+ "sha-1",
+ "slab",
+ "time 0.2.26",
]
[[package]]
@@ -196,18 +273,14 @@ dependencies = [
[[package]]
name = "actix-tls"
-version = "1.0.0"
+version = "2.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "a4e5b4faaf105e9a6d389c606c298dcdb033061b00d532af9df56ff3a54995a8"
+checksum = "24789b7d7361cf5503a504ebe1c10806896f61e96eca9a7350e23001aca715fb"
dependencies = [
- "actix-codec 0.2.0",
- "actix-rt",
+ "actix-codec 0.3.0",
"actix-service",
- "actix-utils 1.0.6",
- "derive_more",
- "either",
- "futures",
- "log",
+ "actix-utils 2.0.0",
+ "futures-util",
]
[[package]]
@@ -250,12 +323,12 @@ dependencies = [
[[package]]
name = "actix-web"
-version = "2.0.0"
+version = "3.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "3158e822461040822f0dbf1735b9c2ce1f95f93b651d7a7aded00b1efbb1f635"
+checksum = "e641d4a172e7faa0862241a20ff4f1f5ab0ab7c279f00c2d4587b77483477b86"
dependencies = [
- "actix-codec 0.2.0",
- "actix-http",
+ "actix-codec 0.3.0",
+ "actix-http 2.2.0",
"actix-macros",
"actix-router",
"actix-rt",
@@ -264,31 +337,34 @@ dependencies = [
"actix-testing",
"actix-threadpool",
"actix-tls",
- "actix-utils 1.0.6",
+ "actix-utils 2.0.0",
"actix-web-codegen",
"awc",
"bytes 0.5.6",
"derive_more",
"encoding_rs",
- "futures",
+ "futures-channel",
+ "futures-core",
+ "futures-util",
"fxhash",
"log",
"mime",
- "net2",
- "pin-project 0.4.27",
+ "pin-project 1.0.5",
"regex",
"serde 1.0.124",
"serde_json",
- "serde_urlencoded",
- "time",
+ "serde_urlencoded 0.7.0",
+ "socket2",
+ "time 0.2.26",
+ "tinyvec",
"url",
]
[[package]]
name = "actix-web-codegen"
-version = "0.2.2"
+version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "a71bf475cbe07281d0b3696abb48212db118e7e23219f13596ce865235ff5766"
+checksum = "ad26f77093333e0e7c6ffe54ebe3582d908a104e448723eec6d43d08b07143fb"
dependencies = [
"proc-macro2",
"quote",
@@ -355,16 +431,17 @@ checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a"
[[package]]
name = "awc"
-version = "1.0.1"
+version = "2.0.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "d7601d4d1d7ef2335d6597a41b5fe069f6ab799b85f53565ab390e7b7065aac5"
+checksum = "b381e490e7b0cfc37ebc54079b0413d8093ef43d14a4e4747083f7fa47a9e691"
dependencies = [
- "actix-codec 0.2.0",
- "actix-http",
+ "actix-codec 0.3.0",
+ "actix-http 2.2.0",
"actix-rt",
"actix-service",
- "base64 0.11.0",
+ "base64 0.13.0",
"bytes 0.5.6",
+ "cfg-if 1.0.0",
"derive_more",
"futures-core",
"log",
@@ -373,7 +450,7 @@ dependencies = [
"rand",
"serde 1.0.124",
"serde_json",
- "serde_urlencoded",
+ "serde_urlencoded 0.7.0",
]
[[package]]
@@ -391,6 +468,12 @@ dependencies = [
]
[[package]]
+name = "base-x"
+version = "0.2.8"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "a4521f3e3d031370679b3b140beb36dfe4801b09ac77e30c61941f97df3ef28b"
+
+[[package]]
name = "base64"
version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -438,6 +521,12 @@ dependencies = [
]
[[package]]
+name = "bumpalo"
+version = "3.6.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "63396b8a4b9de3f4fdfb320ab6080762242f66a8ef174c49d8e19b674db4cdbe"
+
+[[package]]
name = "byteorder"
version = "1.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -495,7 +584,7 @@ dependencies = [
"num-integer",
"num-traits 0.2.14",
"serde 1.0.124",
- "time",
+ "time 0.1.44",
"winapi 0.3.9",
]
@@ -516,6 +605,23 @@ dependencies = [
]
[[package]]
+name = "const_fn"
+version = "0.4.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "28b9d6de7f49e22cf97ad17fc4036ece69300032f45f78f30b4a4482cdc3f4a6"
+
+[[package]]
+name = "cookie"
+version = "0.14.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "03a5d7b21829bc7b4bf4754a978a241ae54ea55a40f92bb20216e54096f4b951"
+dependencies = [
+ "percent-encoding",
+ "time 0.2.26",
+ "version_check",
+]
+
+[[package]]
name = "copyless"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -661,6 +767,12 @@ dependencies = [
]
[[package]]
+name = "discard"
+version = "1.0.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "212d0f5754cb6769937f4501cc0e67f4f4483c8d2c3e1e922ee9edbe4ab4c7c0"
+
+[[package]]
name = "dotenv"
version = "0.15.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -908,7 +1020,8 @@ dependencies = [
name = "gico"
version = "0.1.0"
dependencies = [
- "actix-http",
+ "actix-cors",
+ "actix-http 1.0.1",
"actix-rt",
"actix-service",
"actix-web",
@@ -924,7 +1037,7 @@ dependencies = [
"slog",
"slog-async",
"slog-term",
- "time",
+ "time 0.1.44",
"tokio-pg-mapper",
"tokio-pg-mapper-derive",
"tokio-postgres",
@@ -1143,9 +1256,9 @@ dependencies = [
[[package]]
name = "libc"
-version = "0.2.88"
+version = "0.2.90"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "03b07a082330a35e43f63177cc01689da34fbffa0105e1246cf0311472cac73a"
+checksum = "ba4aede83fc3617411dc6993bc8c70919750c1c257c6ca6a502aed6e0e2394ae"
[[package]]
name = "libgit2-sys"
@@ -1701,6 +1814,16 @@ dependencies = [
]
[[package]]
+name = "resolv-conf"
+version = "0.7.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "52e44394d2086d010551b14b53b1f24e31647570cd1deb0379e2c21b329aba00"
+dependencies = [
+ "hostname",
+ "quick-error",
+]
+
+[[package]]
name = "rust-ini"
version = "0.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1713,6 +1836,15 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6e3bad0ee36814ca07d7968269dd4b7ec89ec2da10c4bb613928d3077083c232"
[[package]]
+name = "rustc_version"
+version = "0.2.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a"
+dependencies = [
+ "semver",
+]
+
+[[package]]
name = "rustversion"
version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1731,6 +1863,21 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd"
[[package]]
+name = "semver"
+version = "0.9.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403"
+dependencies = [
+ "semver-parser",
+]
+
+[[package]]
+name = "semver-parser"
+version = "0.7.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3"
+
+[[package]]
name = "serde"
version = "0.8.23"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1802,6 +1949,31 @@ dependencies = [
]
[[package]]
+name = "serde_urlencoded"
+version = "0.7.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "edfa57a7f8d9c1d260a549e7224100f6c43d43f9103e06dd8b4095a9b2b43ce9"
+dependencies = [
+ "form_urlencoded",
+ "itoa",
+ "ryu",
+ "serde 1.0.124",
+]
+
+[[package]]
+name = "sha-1"
+version = "0.9.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "dfebf75d25bd900fd1e7d11501efab59bc846dbc76196839663e6637bba9f25f"
+dependencies = [
+ "block-buffer",
+ "cfg-if 1.0.0",
+ "cpuid-bool",
+ "digest",
+ "opaque-debug",
+]
+
+[[package]]
name = "sha1"
version = "0.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1890,12 +2062,70 @@ dependencies = [
]
[[package]]
+name = "standback"
+version = "0.2.16"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "decebb311175fdaf1bf8a14583716e93163c566db2ead1c1d608c3e1e4313cb8"
+dependencies = [
+ "version_check",
+]
+
+[[package]]
name = "static_assertions"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f"
[[package]]
+name = "stdweb"
+version = "0.4.20"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "d022496b16281348b52d0e30ae99e01a73d737b2f45d38fed4edf79f9325a1d5"
+dependencies = [
+ "discard",
+ "rustc_version",
+ "stdweb-derive",
+ "stdweb-internal-macros",
+ "stdweb-internal-runtime",
+ "wasm-bindgen",
+]
+
+[[package]]
+name = "stdweb-derive"
+version = "0.5.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "c87a60a40fccc84bef0652345bbbbbe20a605bf5d0ce81719fc476f5c03b50ef"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "serde 1.0.124",
+ "serde_derive",
+ "syn",
+]
+
+[[package]]
+name = "stdweb-internal-macros"
+version = "0.2.9"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "58fa5ff6ad0d98d1ffa8cb115892b6e69d67799f6763e162a1c9db421dc22e11"
+dependencies = [
+ "base-x",
+ "proc-macro2",
+ "quote",
+ "serde 1.0.124",
+ "serde_derive",
+ "serde_json",
+ "sha1",
+ "syn",
+]
+
+[[package]]
+name = "stdweb-internal-runtime"
+version = "0.1.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "213701ba3370744dcd1a12960caa4843b3d68b4d1c0a5d575e0d65b2ee9d16c0"
+
+[[package]]
name = "stringprep"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1952,6 +2182,26 @@ dependencies = [
]
[[package]]
+name = "thiserror"
+version = "1.0.24"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "e0f4a65597094d4483ddaed134f409b2cb7c1beccf25201a9f73c719254fa98e"
+dependencies = [
+ "thiserror-impl",
+]
+
+[[package]]
+name = "thiserror-impl"
+version = "1.0.24"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "7765189610d8241a44529806d6fd1f2e0a08734313a35d5b3a556f92b381f3c0"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "syn",
+]
+
+[[package]]
name = "thread_local"
version = "1.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1981,6 +2231,44 @@ dependencies = [
]
[[package]]
+name = "time"
+version = "0.2.26"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "08a8cbfbf47955132d0202d1662f49b2423ae35862aee471f3ba4b133358f372"
+dependencies = [
+ "const_fn",
+ "libc",
+ "standback",
+ "stdweb",
+ "time-macros",
+ "version_check",
+ "winapi 0.3.9",
+]
+
+[[package]]
+name = "time-macros"
+version = "0.1.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "957e9c6e26f12cb6d0dd7fc776bb67a706312e7299aed74c8dd5b17ebb27e2f1"
+dependencies = [
+ "proc-macro-hack",
+ "time-macros-impl",
+]
+
+[[package]]
+name = "time-macros-impl"
+version = "0.1.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "e5c3be1edfad6027c69f5491cf4cb310d1a71ecd6af742788c6ff8bced86b8fa"
+dependencies = [
+ "proc-macro-hack",
+ "proc-macro2",
+ "quote",
+ "standback",
+ "syn",
+]
+
+[[package]]
name = "tinyvec"
version = "1.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -2147,6 +2435,26 @@ dependencies = [
]
[[package]]
+name = "trust-dns-proto"
+version = "0.19.7"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "1cad71a0c0d68ab9941d2fb6e82f8fb2e86d9945b94e1661dd0aaea2b88215a9"
+dependencies = [
+ "async-trait",
+ "cfg-if 1.0.0",
+ "enum-as-inner",
+ "futures",
+ "idna",
+ "lazy_static",
+ "log",
+ "rand",
+ "smallvec",
+ "thiserror",
+ "tokio",
+ "url",
+]
+
+[[package]]
name = "trust-dns-resolver"
version = "0.18.0-alpha.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -2159,10 +2467,29 @@ dependencies = [
"lazy_static",
"log",
"lru-cache",
- "resolv-conf",
+ "resolv-conf 0.6.3",
"smallvec",
"tokio",
- "trust-dns-proto",
+ "trust-dns-proto 0.18.0-alpha.2",
+]
+
+[[package]]
+name = "trust-dns-resolver"
+version = "0.19.7"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "710f593b371175db53a26d0b38ed2978fafb9e9e8d3868b1acd753ea18df0ceb"
+dependencies = [
+ "cfg-if 0.1.10",
+ "futures",
+ "ipconfig",
+ "lazy_static",
+ "log",
+ "lru-cache",
+ "resolv-conf 0.7.0",
+ "smallvec",
+ "thiserror",
+ "tokio",
+ "trust-dns-proto 0.19.7",
]
[[package]]
@@ -2248,6 +2575,60 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1a143597ca7c7793eff794def352d41792a93c481eb1042423ff7ff72ba2c31f"
[[package]]
+name = "wasm-bindgen"
+version = "0.2.72"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "8fe8f61dba8e5d645a4d8132dc7a0a66861ed5e1045d2c0ed940fab33bac0fbe"
+dependencies = [
+ "cfg-if 1.0.0",
+ "wasm-bindgen-macro",
+]
+
+[[package]]
+name = "wasm-bindgen-backend"
+version = "0.2.72"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "046ceba58ff062da072c7cb4ba5b22a37f00a302483f7e2a6cdc18fedbdc1fd3"
+dependencies = [
+ "bumpalo",
+ "lazy_static",
+ "log",
+ "proc-macro2",
+ "quote",
+ "syn",
+ "wasm-bindgen-shared",
+]
+
+[[package]]
+name = "wasm-bindgen-macro"
+version = "0.2.72"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "0ef9aa01d36cda046f797c57959ff5f3c615c9cc63997a8d545831ec7976819b"
+dependencies = [
+ "quote",
+ "wasm-bindgen-macro-support",
+]
+
+[[package]]
+name = "wasm-bindgen-macro-support"
+version = "0.2.72"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "96eb45c1b2ee33545a813a92dbb53856418bf7eb54ab34f7f7ff1448a5b3735d"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "syn",
+ "wasm-bindgen-backend",
+ "wasm-bindgen-shared",
+]
+
+[[package]]
+name = "wasm-bindgen-shared"
+version = "0.2.72"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "b7148f4696fb4960a346eaa60bbfb42a1ac4ebba21f750f75fc1375b098d5ffa"
+
+[[package]]
name = "widestring"
version = "0.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
diff --git a/Cargo.toml b/Cargo.toml
index cafe258..01b1764 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -6,9 +6,10 @@ edition = "2018"
[dependencies]
actix-rt = "1.0.0"
-actix-web = "2.0.0"
+actix-web = "3.0.0"
actix-http = "1.0.1"
actix-service = "1.0.5"
+actix-cors = "0.5"
tokio-pg-mapper = "0.1.4"
tokio-pg-mapper-derive = "0.1.4"
diff --git a/src/branch/routes.rs b/src/branch/routes.rs
index e46d3ad..bd78f2b 100644
--- a/src/branch/routes.rs
+++ b/src/branch/routes.rs
@@ -26,9 +26,9 @@ async fn index(state: web::Data<AppState>) -> impl Responder {
// Endpoint used for getting branches of a repository
async fn get_repo_branch(
state: web::Data<AppState>,
- repo: web::Path<(String,)>,
+ repo: web::Path<String>,
) -> impl Responder {
- let uuid: Uuid = uuid_from_string(&repo.0);
+ let uuid: Uuid = uuid_from_string(&repo);
info!(state.log, "GET /branch/repo/{}/", &uuid);
let result = Branch::find_by_repo(state.pool.clone(), &uuid).await;
@@ -42,12 +42,12 @@ async fn get_repo_branch(
/// It is a String, casted in an Uuid format.
async fn get_branch(
state: web::Data<AppState>,
- id: web::Path<(String,)>,
+ id: web::Path<String>,
) -> impl Responder {
- let uuid: Uuid = uuid_from_string(&id.0);
+ let uuid: Uuid = uuid_from_string(&id);
let result = Branch::find(state.pool.clone(), &uuid).await;
- info!(state.log, "GET /branch/{}/", id.0);
+ info!(state.log, "GET /branch/{}/", id);
// `map_err` is also used when repo is not found
result
@@ -60,15 +60,15 @@ async fn get_branch(
async fn delete_branch(
req: HttpRequest,
state: web::Data<AppState>,
- id: web::Path<(String,)>,
+ id: web::Path<String>,
) -> impl Responder {
- let uuid: Uuid = uuid_from_string(&id.0);
+ let uuid: Uuid = uuid_from_string(&id);
match req.headers().get(header::AUTHORIZATION) {
Some(x)
if x.to_str().unwrap()
!= env::var("SECRET_KEY").unwrap_or("".to_string()) =>
{
- info!(state.log, "DELETE /branch/{}/ 401", id.0);
+ info!(state.log, "DELETE /branch/{}/ 401", id);
return Err(AppError {
error_type: AppErrorType::AuthorizationError,
message: Some(
@@ -79,13 +79,13 @@ async fn delete_branch(
}
Some(_) => {}
None => {
- info!(state.log, "DELETE /branch/{}/ 400", id.0);
+ info!(state.log, "DELETE /branch/{}/ 400", id);
return Ok(HttpResponse::BadRequest().body(""));
}
};
let result = Branch::delete(state.pool.clone(), &uuid).await;
- info!(state.log, "DELETE /branch/{}/", id.0);
+ info!(state.log, "DELETE /branch/{}/", id);
result
.map(|_| HttpResponse::NoContent().body(""))
@@ -96,13 +96,13 @@ async fn delete_branch(
pub fn config(cfg: &mut web::ServiceConfig) {
cfg.service(
web::scope("/branch")
- .service(web::resource("{_:/?}").route(web::get().to(index)))
+ .service(web::resource("/").route(web::get().to(index)))
.service(
- web::resource("/repo/{repo_id}{_:/?}")
+ web::resource("/repo/{repo_id}/")
.route(web::get().to(get_repo_branch)),
)
.service(
- web::resource("/{id}{_:/?}")
+ web::resource("/{id}/")
.route(web::get().to(get_branch))
.route(web::delete().to(delete_branch)),
),
diff --git a/src/commit/models.rs b/src/commit/models.rs
index b2aa2d2..987bcd2 100644
--- a/src/commit/models.rs
+++ b/src/commit/models.rs
@@ -27,7 +27,7 @@ impl Commit {
pub async fn find_all(pool: Pool) -> Result<Vec<Commit>, AppError> {
let client = get_client(pool.clone()).await.unwrap();
let statement = client
- .prepare("SELECT * FROM commit ORDER BY date DESC")
+ .prepare("SELECT * FROM commit ORDER BY date DESC LIMIT 300")
.await?;
let commits = client
@@ -111,12 +111,12 @@ impl Commit {
"('{}', {}, E'{}', '{}', '{}', E'{}', '{}', E'{}', '{}'),",
commit.hash,
tree,
- commit.text.replace("'", "\\'"),
+ commit.text.replace("\\'", "'").replace("'", "\\'"),
commit.date,
commit.author_email,
- commit.author_name.replace("'", "\\'"),
+ commit.author_name.replace("\\'", "'").replace("'", "\\'"),
commit.committer_email,
- commit.committer_name.replace("'", "\\'"),
+ commit.committer_name.replace("\\'", "'").replace("'", "\\'"),
commit.repository_url
)[..]
}
diff --git a/src/commit/routes.rs b/src/commit/routes.rs
index e49f698..95c0faa 100644
--- a/src/commit/routes.rs
+++ b/src/commit/routes.rs
@@ -23,11 +23,11 @@ async fn index(state: web::Data<AppState>) -> impl Responder {
// Endpoint used for getting one commit
async fn get_commit(
state: web::Data<AppState>,
- hash: web::Path<(String,)>,
+ hash: web::Path<String>,
) -> impl Responder {
- info!(state.log, "GET /commit/{}/", &hash.0);
+ info!(state.log, "GET /commit/{}/", &hash);
- let result = Commit::find(state.pool.clone(), hash.0.clone()).await;
+ let result = Commit::find(state.pool.clone(), hash.clone()).await;
result
.map(|commit| HttpResponse::Ok().json(commit))
@@ -39,14 +39,14 @@ async fn get_commit(
async fn delete_commit(
req: HttpRequest,
state: web::Data<AppState>,
- hash: web::Path<(String,)>,
+ hash: web::Path<String>,
) -> impl Responder {
match req.headers().get(header::AUTHORIZATION) {
Some(x)
if x.to_str().unwrap()
!= env::var("SECRET_KEY").unwrap_or("".to_string()) =>
{
- info!(state.log, "DELETE /commit/{}/ 401", &hash.0);
+ info!(state.log, "DELETE /commit/{}/ 401", &hash);
return Err(AppError {
error_type: AppErrorType::AuthorizationError,
message: Some(
@@ -57,13 +57,13 @@ async fn delete_commit(
}
Some(_) => {}
None => {
- info!(state.log, "DELETE /commit/{}/ 400", &hash.0);
+ info!(state.log, "DELETE /commit/{}/ 400", &hash);
return Ok(HttpResponse::BadRequest().body(""));
}
};
- let result = Commit::delete(state.pool.clone(), &hash.0).await;
- info!(state.log, "DELETE /commit/{}/", &hash.0);
+ let result = Commit::delete(state.pool.clone(), &hash).await;
+ info!(state.log, "DELETE /commit/{}/", &hash);
result
.map(|_| HttpResponse::NoContent().body(""))
@@ -74,9 +74,9 @@ async fn delete_commit(
pub fn config(cfg: &mut web::ServiceConfig) {
cfg.service(
web::scope("/commit")
- .service(web::resource("{_:/?}").route(web::get().to(index)))
+ .service(web::resource("/").route(web::get().to(index)))
.service(
- web::resource("/{hash}{_:/?}")
+ web::resource("/{hash}/")
.route(web::get().to(get_commit))
.route(web::delete().to(delete_commit)),
),
diff --git a/src/email/routes.rs b/src/email/routes.rs
index 14299eb..003d01c 100644
--- a/src/email/routes.rs
+++ b/src/email/routes.rs
@@ -63,13 +63,12 @@ pub fn config(cfg: &mut web::ServiceConfig) {
cfg.service(
web::scope("/email")
.service(
- web::resource("{_:/?}")
+ web::resource("/")
.route(web::get().to(index))
.route(web::post().to(create_email)),
)
.service(
- web::resource("/search{_:/?}")
- .route(web::get().to(search_email)),
+ web::resource("/search/").route(web::get().to(search_email)),
),
);
}
diff --git a/src/main.rs b/src/main.rs
index 2e499f9..6ac5d2b 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -10,9 +10,11 @@ mod commit;
mod email;
mod repository;
-use actix_web::{middleware, App, HttpServer};
+use actix_cors::Cors;
+use actix_web::{http::header, middleware, App, HttpServer};
use dotenv::dotenv;
use slog::info;
+use std::env;
use tokio_postgres::NoTls;
use crate::config::{AppState, Config};
@@ -39,6 +41,21 @@ async fn main() -> std::io::Result<()> {
log: log.clone(),
})
.wrap(middleware::Logger::default())
+ .wrap(
+ Cors::default()
+ .allowed_origin(
+ &env::var("CLIENT")
+ .unwrap_or("http://localhost:8080".to_string())[..]
+ )
+ .allowed_methods(vec!["GET", "POST", "DELETE"])
+ .allowed_headers(vec![
+ header::AUTHORIZATION,
+ header::ACCEPT,
+ ])
+ .allowed_header(header::CONTENT_TYPE)
+ .supports_credentials()
+ .max_age(3600),
+ )
.configure(repository::routes::config)
.configure(email::routes::config)
.configure(commit::routes::config)
diff --git a/src/repository/routes.rs b/src/repository/routes.rs
index 32443b1..d189584 100644
--- a/src/repository/routes.rs
+++ b/src/repository/routes.rs
@@ -27,15 +27,15 @@ async fn index(state: web::Data<AppState>) -> impl Responder {
/// It is a String, casted in an Uuid format.
async fn get_repo(
state: web::Data<AppState>,
- id: web::Path<(String,)>,
+ id: web::Path<String>,
) -> impl Responder {
// I have to match the &id.0 because if it's not a valid Uuid, the server
// must response "Repository not found".
// If I pass a not valid Uuid to Repository::find() it raises an error.
- let uuid: Uuid = uuid_from_string(&id.0);
+ let uuid: Uuid = uuid_from_string(&id);
let result = Repository::find(state.pool.clone(), &uuid).await;
- info!(state.log, "GET /repo/{}/", id.0);
+ info!(state.log, "GET /repo/{}/", id);
// `map_err` is also used when repo is not found
result
@@ -48,9 +48,9 @@ async fn get_repo(
async fn delete_repo(
req: HttpRequest,
state: web::Data<AppState>,
- id: web::Path<(String,)>,
+ id: web::Path<String>,
) -> impl Responder {
- let uuid: Uuid = uuid_from_string(&id.0);
+ let uuid: Uuid = uuid_from_string(&id);
match req.headers().get(header::AUTHORIZATION) {
Some(x)
if x.to_str().unwrap()
@@ -102,12 +102,12 @@ pub fn config(cfg: &mut web::ServiceConfig) {
cfg.service(
web::scope("/repo")
.service(
- web::resource("{_:/?}")
+ web::resource("/")
.route(web::get().to(index))
.route(web::post().to(create_repo)),
)
.service(
- web::resource("/{id}{_:/?}")
+ web::resource("/{id}/")
.route(web::get().to(get_repo))
.route(web::delete().to(delete_repo)),
),