From fff4d8910f25c172f1960cff79d4925b13e3d35f Mon Sep 17 00:00:00 2001 From: theMackabu Date: Sat, 9 Dec 2023 14:50:09 -0800 Subject: [PATCH] release v0.2.1, move out-of poc stage --- Cargo.lock | 2 +- Cargo.toml | 2 +- LICENSE.md | 9 +++++++++ Maidfile.toml | 2 +- README.md | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ app.routes | 6 +++--- src/main.rs | 6 ++---- 7 files changed, 65 insertions(+), 10 deletions(-) create mode 100644 LICENSE.md create mode 100644 README.md diff --git a/Cargo.lock b/Cargo.lock index dfc018a..ea0c5d0 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 348c640..0fd8d89 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 0000000..98fd82f --- /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 aa2e8fa..23f76c5 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 0000000..de411df --- /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 9e860d8..470770a 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 dcb53cd..24f814e 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), -- GitLab