Crates.io | stefn |
lib.rs | stefn |
version | |
source | src |
created_at | 2024-09-29 07:15:32.371435+00 |
updated_at | 2025-01-26 07:04:10.743841+00 |
description | An opinionated and blazingly fast meta framework |
homepage | |
repository | https://github.com/lucas-montes/stefn |
max_upload_size | |
id | 1390669 |
Cargo.toml error: | TOML parse error at line 18, column 1 | 18 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include` |
size | 0 |
Fast and cool meta framework.
Simple and easy.
mod dashboard;
mod website;
use axum::{middleware::from_fn_with_state, Router};
use hyper::{
header::{AUTHORIZATION, CONTENT_TYPE},
Method,
};
use stefn::{
auth::{login_required_middleware, sessions_middleware},
service::Service,
state::WebsiteState,
};
use tower_http::{
cors::{Any, CorsLayer},
services::ServeDir,
};
pub fn create_service() -> Service {
Service::website("WEB_", routes)
}
fn routes(state: WebsiteState) -> Router<WebsiteState> {
Router::new()
.merge(dashboard::routes(state.clone()))
.layer(from_fn_with_state(state.clone(), login_required_middleware))
.merge(website::routes(state.clone()))
.layer(from_fn_with_state(state.clone(), sessions_middleware))
.nest_service("/dist", ServeDir::new("dist"))
.layer(
CorsLayer::new()
.allow_methods([Method::GET, Method::POST, Method::PUT])
.allow_headers([CONTENT_TYPE, AUTHORIZATION])
.allow_origin(Any),
)
.with_state(state)
}
use my_app::create_service;
use stefn::orquestrator::ServicesOrquestrator;
fn main() {
ServicesOrquestrator::default()
.load_environment_variables()
.set_config_from_env()
.enable_migrations()
.add_service(create_service())
.init_dev_tracing()
.run();
}