This commit is contained in:
+100
@@ -0,0 +1,100 @@
|
||||
mod admin;
|
||||
mod i18n;
|
||||
mod migrations;
|
||||
pub mod models;
|
||||
mod public;
|
||||
mod telegram;
|
||||
|
||||
use cot::cli::CliMetadata;
|
||||
use cot::config::{
|
||||
DatabaseConfig, MiddlewareConfig, ProjectConfig, SessionMiddlewareConfig, SessionStoreConfig,
|
||||
SessionStoreTypeConfig,
|
||||
};
|
||||
use cot::db::migrations::SyncDynMigration;
|
||||
use cot::middleware::SessionMiddleware;
|
||||
use cot::project::{MiddlewareContext, RegisterAppsContext, RootHandler};
|
||||
use cot::router::Router;
|
||||
use cot::session::db::SessionApp;
|
||||
use cot::{App, AppBuilder, Project};
|
||||
|
||||
struct PettingApp;
|
||||
|
||||
impl App for PettingApp {
|
||||
fn name(&self) -> &'static str {
|
||||
"web-petting"
|
||||
}
|
||||
|
||||
fn migrations(&self) -> Vec<Box<SyncDynMigration>> {
|
||||
cot::db::migrations::wrap_migrations(migrations::MIGRATIONS)
|
||||
}
|
||||
|
||||
fn router(&self) -> Router {
|
||||
admin::admin_router()
|
||||
}
|
||||
}
|
||||
|
||||
struct PublicApp;
|
||||
|
||||
impl App for PublicApp {
|
||||
fn name(&self) -> &'static str {
|
||||
"public"
|
||||
}
|
||||
|
||||
fn router(&self) -> Router {
|
||||
public::public_router()
|
||||
}
|
||||
}
|
||||
|
||||
struct PettingProject;
|
||||
|
||||
impl Project for PettingProject {
|
||||
fn cli_metadata(&self) -> CliMetadata {
|
||||
cot::cli::metadata!()
|
||||
}
|
||||
|
||||
fn config(&self, _config_name: &str) -> cot::Result<ProjectConfig> {
|
||||
Ok(ProjectConfig::builder()
|
||||
.debug(true)
|
||||
.database(
|
||||
DatabaseConfig::builder()
|
||||
.url("sqlite://db.sqlite3?mode=rwc")
|
||||
.build(),
|
||||
)
|
||||
.middlewares(
|
||||
MiddlewareConfig::builder()
|
||||
.session(
|
||||
SessionMiddlewareConfig::builder()
|
||||
.secure(false)
|
||||
.store(
|
||||
SessionStoreConfig::builder()
|
||||
.store_type(SessionStoreTypeConfig::Database)
|
||||
.build(),
|
||||
)
|
||||
.build(),
|
||||
)
|
||||
.build(),
|
||||
)
|
||||
.build())
|
||||
}
|
||||
|
||||
fn register_apps(&self, apps: &mut AppBuilder, _context: &RegisterAppsContext) {
|
||||
apps.register(SessionApp::new());
|
||||
apps.register_with_views(PublicApp, "");
|
||||
apps.register_with_views(PettingApp, "/admin");
|
||||
}
|
||||
|
||||
fn middlewares(
|
||||
&self,
|
||||
handler: cot::project::RootHandlerBuilder,
|
||||
context: &MiddlewareContext,
|
||||
) -> RootHandler {
|
||||
handler
|
||||
.middleware(SessionMiddleware::from_context(context))
|
||||
.build()
|
||||
}
|
||||
}
|
||||
|
||||
#[cot::main]
|
||||
fn main() -> impl Project {
|
||||
PettingProject
|
||||
}
|
||||
Reference in New Issue
Block a user