Skip to main content

laravel_maintenance/
lib.rs

1//! Database-driven maintenance mode for [Laravel Rust](https://crates.io/crates/laravel-rust).
2//!
3//! Register the provider in `src/app.rs` and run `laravel migrate`:
4//!
5//! ```no_run
6//! use laravel::Application;
7//!
8//! # let _ =
9//! Application::configure().with_providers(|providers| {
10//!     providers.add(laravel_maintenance::MaintenanceServiceProvider);
11//! })
12//! # ;
13//! ```
14//!
15//! Then `laravel maintenance:down --secret=let-me-in` takes the application down for everyone
16//! except the clients that open `/maintenance/let-me-in`. The state lives in the database, so
17//! every server sees it. See the README for the commands, the bypass methods and the settings.
18
19mod commands;
20mod config;
21pub mod events;
22mod maintenance;
23mod middleware;
24pub mod models;
25
26use laravel::config::{Config, Env};
27use laravel::container::Registrar;
28use laravel::foundation::ServiceProvider;
29
30pub use crate::commands::{IpAction, TokenAction};
31pub use crate::config::MaintenanceConfig;
32pub use crate::maintenance::{
33    DownOptions, Downtime, Status, add_ip, add_token, disable, downtime, enable, find_token, flush_cache, hash_token,
34    is_down, is_ip_allowed, is_token_allowed, remove_ip, revoke_token, status,
35};
36pub use crate::middleware::check_maintenance_mode;
37
38/// Adds the package's settings, migrations, 503 view, commands, and the global
39/// [`check_maintenance_mode`] middleware.
40pub struct MaintenanceServiceProvider;
41
42laravel::db::migrations!(fn migrations = "database/migrations");
43
44impl ServiceProvider for MaintenanceServiceProvider {
45    fn config(&self, config: &mut Config, env: &Env) {
46        config.discover(env!("CARGO_CRATE_NAME"), env);
47    }
48
49    fn register(&self, app: &mut Registrar) {
50        app.discover(env!("CARGO_CRATE_NAME"));
51        app.migrations().add(migrations());
52        app.views().namespace("maintenance", laravel::embed!("resources/views"));
53        app.middleware().append(check_maintenance_mode);
54    }
55}