diff --git a/Cargo.lock b/Cargo.lock index dfc018ada5378aab89924601647950120e6f19ea..ea0c5d0247799d4ca57a5c180156327217c1fd73 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1302,7 +1302,7 @@ checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" [[package]] name = "script" -version = "0.2.0" +version = "0.2.1" dependencies = [ "actix-web", "fancy-regex", diff --git a/Cargo.toml b/Cargo.toml index 348c640c5e35e0810406177a013832bc1971f0f0..0fd8d89176b2a345eb1aec546f3c80aae7fcd4c5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "script" -version = "0.2.0" +version = "0.2.1" edition = "2021" license = "MIT" repository = "https://lab.themackabu.dev/self/script" diff --git a/LICENSE.md b/LICENSE.md new file mode 100644 index 0000000000000000000000000000000000000000..98fd82f1f960ec2fa4311c3f281b94986ad8548f --- /dev/null +++ b/LICENSE.md @@ -0,0 +1,9 @@ +# MIT License + +### Copyright (c) 2023 theMackabu [theMackabu@gmail.com] + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +_The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software._ + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/Maidfile.toml b/Maidfile.toml index aa2e8fa5328a2ae9f7ec2540daf5d851ddde99c2..23f76c5d76f72c8f80f8efdcf64b6c704477635f 100644 --- a/Maidfile.toml +++ b/Maidfile.toml @@ -1,6 +1,6 @@ [project] name = "script" -version = "0.2.0" +version = "0.2.1" [tasks] clean = { script = ["rm -rf bin", "mkdir bin"] } diff --git a/README.md b/README.md new file mode 100644 index 0000000000000000000000000000000000000000..de411dfe49f5f83aad48054d3ce3c6a091cf0bb5 --- /dev/null +++ b/README.md @@ -0,0 +1,48 @@ +# barebones http scripting + +## Overview + +Define routes on runtime and execute scripts associated with each route. The server supports fetching data, for proxy purposes. + +## Usage + +````rust +// the index route +index { + text(":3\nwelcome to the root") +} + +// this is /hello +hello() { + text("Hello World!") +} + +// get data from another website, then return as json +get() { + json(http::get("https://httpbin.org/json").json()) +} +``` + +For more syntax, check out `app.routes` + + +```bash +# Start the server +script start +```` + +For more commands, check out `script --help` + +### Installation + +Pre-built binaries for Linux, MacOS, and Windows can be found on the [releases](releases) page. + +Install from crates.io using `cargo install script` + +#### Building + +- Clone the project +- Open a terminal in the project folder +- Check if you have cargo (Rust's package manager) installed, just type in `cargo` +- If cargo is installed, run `cargo build --release` +- Put the executable into one of your PATH entries, usually `/bin/` or `/usr/bin/` diff --git a/app.routes b/app.routes index 9e860d821821e3f3994461fd5afff20240444c31..470770adf95f4f43a5e0ada091a1ffd777e871bd 100644 --- a/app.routes +++ b/app.routes @@ -11,7 +11,7 @@ example() { } example/json() { - let res = http::get("https://httpbin.org//json"); + let res = http::get("https://httpbin.org/json"); let body = #{ response: res.json(), info: #{ @@ -25,13 +25,13 @@ example/json() { json(body) } -example/post() { +example/post/bin() { let body = #{ hello: "world", url: url, }; - json(http::post("https://httpbin.org//post", body).raw()) + json(http::post("https://httpbin.org/post", body).raw()) } test.json() { diff --git a/src/main.rs b/src/main.rs index dcb53cde282024f56c3d48020ad6ee499982d418..24f814eb92f78ac8bda7df51b183d1dae6cbbb69 100644 --- a/src/main.rs +++ b/src/main.rs @@ -16,10 +16,10 @@ use actix_web::{get, http::header::ContentType, http::StatusCode, web::Path, App lazy_static! { static ref R_INDEX: Result = Regex::new(r"index\s*\{"); static ref R_ERR: Result = Regex::new(r"(\b\d{3})\s*\{"); - static ref R_DOT: Result = Regex::new(r"\.(\w+)\(\)\s*\{"); static ref R_FN: Result = Regex::new(r"(\w+)\((.*?)\)\s*\{"); + static ref R_DOT: Result = Regex::new(r"\.(\w+)\((.*?)\)\s*\{"); static ref R_WILD: Result = Regex::new(r"\*\s*\{|wildcard\s*\{"); - static ref R_SLASH: Result = Regex::new(r"(?<=[a-zA-Z])/(?=[a-zA-Z])"); + static ref R_SLASH: Result = Regex::new(r"(?m)\/(?=.*\((.*?)\)\s*\{[^{]*$)"); } fn rm_first(s: &str) -> &str { @@ -270,8 +270,6 @@ async fn handler(url: Path, req: HttpRequest) -> impl Responder { ternary!(has_wildcard, R_WILD.as_ref().unwrap().replace_all(&result, "fn _wildcard(err) {").to_string(), result) }; - println!("{contents}"); - let mut ast = match engine.compile(contents) { Ok(ast) => ast, Err(err) => error(&engine, &path, err),