Add cookie based auth, file serving and uploading

This commit is contained in:
2024-11-03 01:25:28 +01:00
parent c83c0e7ec4
commit 5c69317660
19 changed files with 418 additions and 45 deletions

View File

@@ -8,6 +8,7 @@ use loco_rs::{
controller::AppRoutes,
db::{self, truncate_table},
environment::Environment,
storage::{self, Storage},
task::Tasks,
Result,
};
@@ -47,6 +48,7 @@ impl Hooks for App {
fn routes(_ctx: &AppContext) -> AppRoutes {
AppRoutes::with_default_routes() // controller routes below
.add_route(controllers::data::routes())
.add_route(controllers::auth::routes())
.add_route(controllers::website::routes())
}
@@ -56,8 +58,18 @@ impl Hooks for App {
Ok(())
}
async fn after_context(ctx: AppContext) -> Result<AppContext> {
let store = storage::drivers::local::new_with_prefix("uploads").map_err(Box::from)?;
Ok(AppContext {
storage: Storage::single(store).into(),
..ctx
})
}
fn register_tasks(tasks: &mut Tasks) {
tasks.register(tasks::seed::SeedData);
tasks.register(tasks::create_user::CreateUserData);
}
async fn truncate(db: &DatabaseConnection) -> Result<()> {