Skip to content

Commit

Permalink
Merge pull request #49 from ngyn-rs/dev
Browse files Browse the repository at this point in the history
chore(release): v0.2.5
  • Loading branch information
elcharitas authored Nov 4, 2023
2 parents e0b526f + cf04092 commit 463cd52
Show file tree
Hide file tree
Showing 27 changed files with 135 additions and 150 deletions.
80 changes: 23 additions & 57 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ Ngyn is a lightweight and powerful framework for creating robust applications in
- **Powerful Macros**: Ngyn provides a set of powerful macros that simplify common tasks.
- **Lightweight**: Ngyn is lightweight and has a minimal footprint, making it a great choice for projects of all sizes.
- **High Performance**: Ngyn is built with performance in mind. It leverages the power of Rust to deliver fast, efficient web apps.
- **Route Gates** (WIP): A simplified way to restrict access to a route based on a set condition
- **Route Gates**: A simplified way to restrict access to a route based on a set condition
- **Fully Extensible**: Ngyn allows you to build your own platform engines or make use of any of the built-in `vercel` or `tide` platform engines.

## Get Started

Expand All @@ -19,13 +20,13 @@ Ngyn is a great choice for creating robust applications quickly and easily. With

```rust
use modules::MyAppModule;
use ngyn::{NgynFactory, Result};
use ngyn::{NgynFactory, NgynRequest, NgynResponse, Result};

#[tokio::main]
#[ngyn::main]
async fn main() -> Result<()> {
let app = NgynFactory::create::<MyAppModule>();

app.get("/", |req, res| {
app.get("/", |req: &NgynRequest, res: &mut NgynResponse| {
res.send("Hello World!");
});

Expand Down
9 changes: 5 additions & 4 deletions crates/core/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "ngyn"
version = "0.2.4"
version = "0.2.5"
edition = "2021"
description = "Modular backend framework for web applications"
license = "MIT"
Expand All @@ -11,10 +11,11 @@ path = "src/lib.rs"
[dependencies]
async-std = { version = "1.6.0", features = ["attributes"] }
nject = "0.3.0"
ngyn_macros = { path = "../macros", version = "0.2.4" }
ngyn_shared = { path = "../shared", version = "0.2.4" }
tide = "0.16.0"
ngyn_macros = { path = "../macros", version = "0.2.5" }
ngyn_shared = { path = "../shared", version = "0.2.5" }
tide = { version = "0.16.0", optional = true }
vercel_runtime = { version = "1.1.0", optional = true }

[features]
tide = ["dep:tide", "ngyn_shared/tide"]
vercel = ["dep:vercel_runtime"]
12 changes: 7 additions & 5 deletions crates/core/src/app/factory.rs
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
use crate::server::{NgynApplication, NgynEngine};
#[cfg(feature = "tide")]
use crate::platforms::NgynApplication;

use ngyn_shared::{enums::HttpMethod, NgynModule, NgynRequest, NgynResponse};
use ngyn_shared::{enums::HttpMethod, NgynEngine, NgynModule, NgynRequest, NgynResponse};

/// The `NgynFactory` struct is used to create instances of `NgynEngine`.
pub struct NgynFactory<Application: NgynEngine> {
/// this is just a placeholder and would prolly not be used
_app: Application,
}

#[cfg(feature = "tide")]
impl NgynFactory<NgynApplication> {
pub fn create<AppModule: NgynModule>() -> NgynApplication {
Self::build::<AppModule>()
}
}

#[cfg(feature = "vercel")]
impl NgynFactory<crate::server::VercelApplication> {
pub fn create<AppModule: NgynModule>() -> crate::server::VercelApplication {
impl NgynFactory<crate::platforms::VercelApplication> {
pub fn create<AppModule: NgynModule>() -> crate::platforms::VercelApplication {
Self::build::<AppModule>()
}
}
Expand All @@ -28,7 +30,7 @@ impl<Application: NgynEngine> NgynFactory<Application> {
/// ### Example
///
/// ```
/// use ngyn::{module, NgynFactory, server::NgynApplication};
/// use ngyn::{module, NgynFactory, platforms::NgynApplication};
///
/// #[module]
/// pub struct YourAppModule;
Expand Down
6 changes: 4 additions & 2 deletions crates/core/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
pub mod app;
pub mod server;
pub mod platforms;

pub use crate::app::factory::*;
pub use crate::app::provider::*;
pub use async_std::main;
pub use ngyn_macros::*;
pub use ngyn_shared::*;
pub use nject::{injectable as dependency, provider};
pub use tide::{utils::async_trait, Result};

#[cfg(feature = "tide")]
pub type Result<T> = tide::Result<T>;
9 changes: 9 additions & 0 deletions crates/core/src/platforms/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#[cfg(feature = "tide")]
pub mod tide;
#[cfg(feature = "vercel")]
pub mod vercel;

#[cfg(feature = "tide")]
pub use tide::*;
#[cfg(feature = "vercel")]
pub use vercel::*;
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
use ngyn_shared::{HttpMethod, NgynRequest, NgynResponse};
use ngyn_shared::{Handler, HttpMethod, NgynEngine, NgynRequest, NgynResponse};
use std::sync::Arc;
use tide::{Result, Server};

use super::{Handler, NgynEngine};

/// `NgynApplication` is a struct that represents a server instance in the Ngyn framework.
pub struct NgynApplication {
server: Server<()>,
Expand All @@ -24,8 +22,7 @@ impl NgynEngine for NgynApplication {
let handler = Arc::clone(&handler);
async move {
let request = NgynRequest::from(req);
let mut response = NgynResponse::from_status(404);
response.body("Route not found");
let mut response = NgynResponse::new();
handler.handle(&request, &mut response);
response.await.build()
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
use ngyn_shared::HttpMethod;

#[cfg(feature = "vercel")]
use vercel_runtime::{Body, Error, Request, Response};

use super::{Handler, NgynEngine};
Expand All @@ -20,7 +18,6 @@ impl NgynEngine for VercelApplication {
}
}

#[cfg(feature = "vercel")]
impl VercelApplication {
pub fn get(&mut self, path: &str, handler: impl Handler) -> &mut Self {
self.route(path, HttpMethod::Get, Box::new(handler))
Expand Down Expand Up @@ -58,6 +55,8 @@ impl VercelApplication {
headers,
body.to_vec(),
));
// change the status code to 200 to prevent vercel from returning a 404
res.set_status(200).body("");
handler.handle(&req, &mut res);
break; // Exit the loop once a route is found
}
Expand Down
7 changes: 0 additions & 7 deletions crates/core/src/server/mod.rs

This file was deleted.

4 changes: 2 additions & 2 deletions crates/macros/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "ngyn_macros"
version = "0.2.4"
version = "0.2.5"
edition = "2021"
description = "Modular backend framework for web applications"
license = "MIT"
Expand All @@ -9,7 +9,7 @@ license = "MIT"
nject = "0.3.0"
syn = "2.0.29"
quote = "1.0.33"
ngyn_shared = { path = "../shared", version = "0.2.4" }
ngyn_shared = { path = "../shared", version = "0.2.5" }

[lib]
path = "src/lib.rs"
Expand Down
8 changes: 6 additions & 2 deletions crates/shared/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
[package]
name = "ngyn_shared"
version = "0.2.4"
version = "0.2.5"
edition = "2021"
description = "Modular backend framework for web applications"
license = "MIT"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
async-trait = "0.1.74"
nject = "0.3.0"
tide = "0.16.0"
tide = { version = "0.16.0", optional = true }

[features]
tide = ["dep:tide"]
Original file line number Diff line number Diff line change
@@ -1,17 +1,5 @@
use ngyn_shared::{HttpMethod, NgynRequest, NgynResponse};

pub trait Handler: Sync + Send + 'static {
fn handle(&self, req: &NgynRequest, res: &mut NgynResponse);
}

impl<F> Handler for F
where
F: Fn(&NgynRequest, &mut NgynResponse) + Send + Sync + 'static,
{
fn handle(&self, req: &NgynRequest, res: &mut NgynResponse) {
self(req, res)
}
}
use super::Handler;
use crate::HttpMethod;

pub trait NgynEngine {
/// Creates a new instance of `NgynApplication` with a new `Server`
Expand All @@ -29,7 +17,7 @@ pub trait NgynEngine {
/// ### Example
///
/// ```
/// use ngyn::{server::{NgynApplication, NgynEngine}, HttpMethod, NgynRequest, NgynResponse};
/// use ngyn::{platforms::{NgynApplication, NgynEngine}, HttpMethod, NgynRequest, NgynResponse};
///
/// let mut server = NgynApplication::new();
/// server.route("/", HttpMethod::Get, Box::new(|req: &NgynRequest, res: &mut NgynResponse| {
Expand Down
Loading

0 comments on commit 463cd52

Please sign in to comment.