From e08386ceea16202e6ebf0028b74525c7cb224dd1 Mon Sep 17 00:00:00 2001 From: Elad Kaplan Date: Thu, 30 May 2024 09:58:11 +0300 Subject: [PATCH 1/5] docs --- docs-site/content/docs/getting-started/cli.md | 25 ++++++++ .../content/docs/getting-started/config.md | 10 +-- .../docs/getting-started/deployment.md | 62 +++++++++---------- docs-site/content/docs/the-app/errors.md | 3 +- .../content/docs/the-app/initializers.md | 50 ++++++++++----- docs-site/content/docs/the-app/models.md | 36 +++++++---- examples/demo/Cargo.lock | 2 +- examples/demo/config/development.yaml | 2 +- examples/demo/src/app.rs | 2 + examples/demo/src/models/users.rs | 3 + snipdoc.yml | 3 + src/app.rs | 2 + 12 files changed, 133 insertions(+), 67 deletions(-) diff --git a/docs-site/content/docs/getting-started/cli.md b/docs-site/content/docs/getting-started/cli.md index 873760991..f72b71dfd 100644 --- a/docs-site/content/docs/getting-started/cli.md +++ b/docs-site/content/docs/getting-started/cli.md @@ -35,6 +35,31 @@ cargo loco --help ``` + +```sh +The one-person framework for Rust + +Usage: blo-cli [OPTIONS] + +Commands: + start Start an app + db Perform DB operations + routes Describe all application endpoints + task Run a custom task + generate code generation creates a set of files and code templates based on a predefined set of rules + doctor Validate and diagnose configurations + version Display the app version + help Print this message or the help of the given subcommand(s) + +Options: + -e, --environment Specify the environment [default: development] + -h, --help Print help + -V, --version Print version + +``` + + + You can now drive your development through the CLI: ``` diff --git a/docs-site/content/docs/getting-started/config.md b/docs-site/content/docs/getting-started/config.md index 70f9cd305..2a3e3d775 100644 --- a/docs-site/content/docs/getting-started/config.md +++ b/docs-site/content/docs/getting-started/config.md @@ -70,13 +70,13 @@ LOCO_ENV=qa cargo loco start ## Settings The configuration files contain knobs to set up your Loco app. You can also have your custom settings, with the `settings:` section. in `config/development.yaml` add the `settings:` section - -```yaml - settings: + +```yaml +settings: allow_list: - google.com - - apple.com - ``` + - apple.com +``` These setting will appear in `ctx.config.settings` as `serde_json::Value`. You can create your strongly typed settings by adding a struct: diff --git a/docs-site/content/docs/getting-started/deployment.md b/docs-site/content/docs/getting-started/deployment.md index bd127be30..cc9683bab 100644 --- a/docs-site/content/docs/getting-started/deployment.md +++ b/docs-site/content/docs/getting-started/deployment.md @@ -35,9 +35,9 @@ There are a few configuration sections that are important to review and set acco - Logger: - -```yaml - # Application logging configuration + +```yaml +# Application logging configuration logger: # Enable or disable logging. enable: true @@ -49,28 +49,28 @@ logger: format: compact # By default the logger has filtering only logs that came from your code or logs that came from `loco` framework. to see all third party libraries # Uncomment the line below to override to see all third party libraries you can enable this config and override the logger filters. - # override_filter: trace - ``` + # override_filter: trace +``` - Server: - -```yaml - server: + +```yaml +server: # Port on which the server will listen. the server binding is 0.0.0.0:{PORT} port: {{get_env(name="NODE_PORT", default=3000)}} # The UI hostname or IP address that mailers will point to. host: http://localhost - # Out of the box middleware configuration. to disable middleware you can changed the `enable` field to `false` of comment the middleware block - ``` + # Out of the box middleware configuration. to disable middleware you can changed the `enable` field to `false` of comment the middleware block +``` - Database: - -```yaml - database: + +```yaml +database: # Database connection URI uri: {{get_env(name="DATABASE_URL", default="postgres://loco:loco@localhost:5432/loco_app")}} # When enabled, the sql query will be logged. @@ -88,19 +88,19 @@ logger: # Truncate database when application loaded. This is a dangerous operation, make sure that you using this flag only on dev environments or test mode dangerously_truncate: false # Recreating schema when application loaded. This is a dangerous operation, make sure that you using this flag only on dev environments or test mode - dangerously_recreate: false - ``` + dangerously_recreate: false +``` - Mailer: - -```yaml - mailer: + +```yaml +mailer: # SMTP mailer configuration. smtp: # Enable/Disable smtp mailer. - enable: true + host: {{get_env(name="MAILER_HOST", default="localhost") }} # SMTP server host. e.x localhost, smtp.gmail.com host: localhost # SMTP server port @@ -109,32 +109,32 @@ logger: secure: false # auth: # user: - # password: - ``` + # password: +``` - Queue: - -```yaml - queue: + +```yaml +queue: # Redis connection URI uri: {{get_env(name="REDIS_URL", default="redis://127.0.0.1")}} # Dangerously flush all data in Redis on startup. dangerous operation, make sure that you using this flag only on dev environments or test mode - dangerously_flush: false - ``` + dangerously_flush: false +``` - JWT secret: - -```yaml - auth: + +```yaml +auth: # JWT authentication jwt: # Secret key for token generation and verification secret: PqRwLF2rhHe8J22oBeHy # Token expiration time in seconds - expiration: 604800 # 7 days - ``` + expiration: 604800 # 7 days +``` diff --git a/docs-site/content/docs/the-app/errors.md b/docs-site/content/docs/the-app/errors.md index 53ce345ce..84c74441d 100644 --- a/docs-site/content/docs/the-app/errors.md +++ b/docs-site/content/docs/the-app/errors.md @@ -21,7 +21,7 @@ flair =[] As a reminder, error levels and their logging can be controlled in your `development.yaml`: ### Logger - + ```yaml # Application logging configuration logger: @@ -37,6 +37,7 @@ logger: # Uncomment the line below to override to see all third party libraries you can enable this config and override the logger filters. # override_filter: trace ``` + The most important knobs here are: diff --git a/docs-site/content/docs/the-app/initializers.md b/docs-site/content/docs/the-app/initializers.md index a0a1c1a61..bde50d9c2 100644 --- a/docs-site/content/docs/the-app/initializers.md +++ b/docs-site/content/docs/the-app/initializers.md @@ -20,15 +20,28 @@ Initializers are a way to encapsulate a piece of infrastructure "wiring" that yo ### Writing initializers Currently, an initializer is anything that implements the `Initializer` trait: - + ```rust -// implement this and place your code in `src/initializers/` -pub trait Initializer { +pub trait Initializer: Sync + Send { + /// The initializer name or identifier fn name(&self) -> String; - async fn before_run(&self, _app_context: &AppContext) -> Result<()>; - async fn after_routes(&self, router: AxumRouter, _ctx: &AppContext) -> Result; + + /// Occurs after the app's `before_run`. + /// Use this to for one-time initializations, load caches, perform web + /// hooks, etc. + async fn before_run(&self, _app_context: &AppContext) -> Result<()> { + Ok(()) + } + + /// Occurs after the app's `after_routes`. + /// Use this to compose additional functionality and wire it into an Axum + /// Router + async fn after_routes(&self, router: AxumRouter, _ctx: &AppContext) -> Result { + Ok(router) + } } ``` + ### Example: Integrating Axum Session @@ -78,19 +91,26 @@ src/ After you've implemented your own initializer, you should implement the `initializers(..)` hook in your `src/app.rs` and provide a Vec of your initializers: - + ```rust -// in src/app.rs -impl Hooks for App { - // return a vec of boxed initializers (`Box`) - // lets Loco know what to use. - async fn initializers(_ctx: &AppContext) -> Result>> { - Ok(vec![Box::new( - initializers::axum_session::AxumSessionInitializer, - )]) + async fn initializers(ctx: &AppContext) -> Result>> { + let mut initializers: Vec> = vec![ + Box::new(initializers::axum_session::AxumSessionInitializer), + Box::new(initializers::view_engine::ViewEngineInitializer), + Box::new(initializers::hello_view_engine::HelloViewEngineInitializer), + Box::new(loco_extras::initializers::normalize_path::NormalizePathInitializer), + ]; + + if ctx.environment != Environment::Test { + initializers.push(Box::new( + loco_extras::initializers::prometheus::AxumPrometheusInitializer, + )); + } + + Ok(initializers) } -} ``` + Loco will now run your initializer stack in the correct places during the app boot process. diff --git a/docs-site/content/docs/the-app/models.md b/docs-site/content/docs/the-app/models.md index 70635dc55..08ce9986a 100644 --- a/docs-site/content/docs/the-app/models.md +++ b/docs-site/content/docs/the-app/models.md @@ -275,11 +275,8 @@ Having said that, it's up to you to code your data fixes in a `task` or `migrati We use the [validator](https://docs.rs/validator) library under the hood. First, build your validator with the constraints you need, and then implement `Validatable` for your `ActiveModel`. + ```rust -// in models/user.rs - -use loco_rs::prelude::*; - #[derive(Debug, Validate, Deserialize)] pub struct Validator { #[validate(length(min = 2, message = "Name must be at least 2 characters long."))] @@ -297,6 +294,8 @@ impl Validatable for super::_entities::users::ActiveModel { } } ``` + + Note that `Validatable` is how you instruct Loco which `Validator` to provide and how to build it from a model. @@ -366,21 +365,32 @@ Using `via()` will cause `find_related` to walk through the link table without y Model configuration that's available to you is exciting because it controls all aspects of development, testing, and production, with a ton of goodies, coming from production experience. + ```yaml -# .. other sections .. - database: - uri: postgres://localhost:5432/rr_app - # uri: sqlite://db.sqlite?mode=rwc + # Database connection URI + uri: {{get_env(name="DATABASE_URL", default="postgres://loco:loco@localhost:5432/loco_app")}} + # When enabled, the sql query will be logged. enable_logging: false + # Set the timeout duration when acquiring a connection. + connect_timeout: 500 + # Set the idle duration before closing a connection. + idle_timeout: 500 + # Minimum number of connections for a pool. min_connections: 1 + # Maximum number of connections for a pool. max_connections: 1 + # Run migration up when application loaded auto_migrate: true - dangerously_truncate: true - dangerously_recreate: true + # Truncate database when application loaded. This is a dangerous operation, make sure that you using this flag only on dev environments or test mode + dangerously_truncate: false + # Recreating schema when application loaded. This is a dangerous operation, make sure that you using this flag only on dev environments or test mode + dangerously_recreate: false ``` + -By combining these flags, you can create different expriences to help you be more productive. + +By combining these flags, you can create different experiences to help you be more productive. You can truncate before an app starts -- which is useful for running tests, or you can recreate the entire DB when the app starts -- which is useful for integration tests or setting up a new environment. In production, you want these turned off (hence the "dangerously" part). @@ -665,6 +675,7 @@ In some cases, you may want to run tests with a clean dataset, ensuring that eac - When doing it recommended to run all the relevant task in with [serial](https://crates.io/crates/rstest) crate. - To decide which tables you want to truncate, add the entity model to the App hook: + ```rust pub struct App; #[async_trait] @@ -681,7 +692,6 @@ impl Hooks for App { ## Seeding - ```rust #[tokio::test] #[serial] @@ -709,7 +719,7 @@ in the following example you can use `cleanup_user_model` which clean all user m #[tokio::test] #[serial] -async fn can_cerate_user() { +async fn can_create_user() { testing::request::(|request, _ctx| async move { // create user test with_settings!({ diff --git a/examples/demo/Cargo.lock b/examples/demo/Cargo.lock index 22a376ae7..0d81ed057 100644 --- a/examples/demo/Cargo.lock +++ b/examples/demo/Cargo.lock @@ -2854,7 +2854,7 @@ dependencies = [ [[package]] name = "loco-rs" -version = "0.4.0" +version = "0.5.0" dependencies = [ "argon2", "async-trait", diff --git a/examples/demo/config/development.yaml b/examples/demo/config/development.yaml index ceb527184..869ba5771 100644 --- a/examples/demo/config/development.yaml +++ b/examples/demo/config/development.yaml @@ -91,7 +91,7 @@ mailer: # SMTP mailer configuration. smtp: # Enable/Disable smtp mailer. - enable: true + host: {{get_env(name="MAILER_HOST", default="localhost") }} # SMTP server host. e.x localhost, smtp.gmail.com host: localhost # SMTP server port diff --git a/examples/demo/src/app.rs b/examples/demo/src/app.rs index 97eae6292..f49469eaa 100644 --- a/examples/demo/src/app.rs +++ b/examples/demo/src/app.rs @@ -43,6 +43,7 @@ impl Hooks for App { env!("CARGO_CRATE_NAME") } + // async fn initializers(ctx: &AppContext) -> Result>> { let mut initializers: Vec> = vec![ Box::new(initializers::axum_session::AxumSessionInitializer), @@ -59,6 +60,7 @@ impl Hooks for App { Ok(initializers) } + // fn routes(ctx: &AppContext) -> AppRoutes { AppRoutes::with_default_routes() diff --git a/examples/demo/src/models/users.rs b/examples/demo/src/models/users.rs index 8fbf27d1d..c44323aa3 100644 --- a/examples/demo/src/models/users.rs +++ b/examples/demo/src/models/users.rs @@ -20,6 +20,7 @@ pub struct RegisterParams { pub name: String, } +// #[derive(Debug, Validate, Deserialize)] pub struct Validator { #[validate(length(min = 2, message = "Name must be at least 2 characters long."))] @@ -27,6 +28,7 @@ pub struct Validator { #[validate(custom = "validation::is_valid_email")] pub email: String, } + impl Validatable for super::_entities::users::ActiveModel { fn validator(&self) -> Box { Box::new(Validator { @@ -35,6 +37,7 @@ impl Validatable for super::_entities::users::ActiveModel { }) } } +// #[async_trait::async_trait] impl ActiveModelBehavior for super::_entities::users::ActiveModel { diff --git a/snipdoc.yml b/snipdoc.yml index 0883e2855..a21a342b8 100644 --- a/snipdoc.yml +++ b/snipdoc.yml @@ -8,6 +8,9 @@ snippets: cargo loco --help ``` path: ./snipdoc.yml + exec-help-command: + content: cd ./examples/demo && cargo loco --help + path: ./snipdoc.yml build-command: content: |- ```sh diff --git a/src/app.rs b/src/app.rs index 0dab04631..9e8035ef5 100644 --- a/src/app.rs +++ b/src/app.rs @@ -190,6 +190,7 @@ pub trait Hooks { /// An initializer. /// Initializers should be kept in `src/initializers/` #[async_trait] +// pub trait Initializer: Sync + Send { /// The initializer name or identifier fn name(&self) -> String; @@ -208,3 +209,4 @@ pub trait Initializer: Sync + Send { Ok(router) } } +// From c7260b6915f6ce58d9b6ef6c764c100a204b859c Mon Sep 17 00:00:00 2001 From: Elad Kaplan Date: Fri, 31 May 2024 08:51:40 +0300 Subject: [PATCH 2/5] fix config --- examples/demo/config/development.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/demo/config/development.yaml b/examples/demo/config/development.yaml index 869ba5771..4996f46ed 100644 --- a/examples/demo/config/development.yaml +++ b/examples/demo/config/development.yaml @@ -91,9 +91,9 @@ mailer: # SMTP mailer configuration. smtp: # Enable/Disable smtp mailer. - host: {{get_env(name="MAILER_HOST", default="localhost") }} + enable: true # SMTP server host. e.x localhost, smtp.gmail.com - host: localhost + host: {{get_env(name="MAILER_HOST", default="localhost") }} # SMTP server port port: 1025 # Use secure connection (SSL/TLS). From 659188d59af73b6a29d8c6b693b236e6408e7a75 Mon Sep 17 00:00:00 2001 From: Elad Kaplan Date: Fri, 31 May 2024 09:01:39 +0300 Subject: [PATCH 3/5] alignment docs --- docs-site/content/docs/getting-started/deployment.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs-site/content/docs/getting-started/deployment.md b/docs-site/content/docs/getting-started/deployment.md index cc9683bab..d177ede10 100644 --- a/docs-site/content/docs/getting-started/deployment.md +++ b/docs-site/content/docs/getting-started/deployment.md @@ -100,9 +100,9 @@ mailer: # SMTP mailer configuration. smtp: # Enable/Disable smtp mailer. - host: {{get_env(name="MAILER_HOST", default="localhost") }} + enable: true # SMTP server host. e.x localhost, smtp.gmail.com - host: localhost + host: {{get_env(name="MAILER_HOST", default="localhost") }} # SMTP server port port: 1025 # Use secure connection (SSL/TLS). From ed2e49dc8abd234752069ed19f7767ee0bab4ab6 Mon Sep 17 00:00:00 2001 From: Elad Kaplan Date: Fri, 31 May 2024 09:10:42 +0300 Subject: [PATCH 4/5] change ci --- .github/workflows/docs.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index b2eac0eb5..589ed0d65 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -27,7 +27,9 @@ jobs: toolchain: ${{ env.RUST_TOOLCHAIN }} override: true components: rustfmt - - run: cargo install snipdoc + - run: cargo install snipdoc --features exec - run: snipdoc check + env: + SNIPDOC_SKIP_EXEC_COMMANDS: true \ No newline at end of file From 8c4fa04122cdbbed9e1fec18ccb4b673164d6a90 Mon Sep 17 00:00:00 2001 From: Elad Kaplan Date: Tue, 4 Jun 2024 14:05:57 +0300 Subject: [PATCH 5/5] change to use templates --- README.md | 8 ++-- docs-site/content/docs/getting-started/cli.md | 6 +-- .../content/docs/getting-started/config.md | 2 +- .../docs/getting-started/deployment.md | 4 +- .../content/docs/getting-started/guide.md | 18 ++++----- .../content/docs/getting-started/starters.md | 4 +- .../docs/getting-started/tour/index.md | 12 +++--- snipdoc.yml | 37 +++---------------- 8 files changed, 31 insertions(+), 60 deletions(-) diff --git a/README.md b/README.md index e2fb037ea..0d9f7d4b5 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ #### Loco is strongly inspired by Rails. If you know Rails and Rust, you'll feel at home. If you only know Rails and new to Rust, you'll find Loco refreshing. We do not assume you know Rails. ## Quick Start - + ```sh cargo install loco-cli cargo install sea-orm-cli # Only when DB is needed @@ -30,7 +30,7 @@ cargo install sea-orm-cli # Only when DB is needed Now you can create your new app (choose "`SaaS` app"). - + ```sh ❯ loco new ✔ ❯ App name? · myapp @@ -44,13 +44,11 @@ myapp To configure a database , please run a local postgres database with loco:loco and a db named [insert app]_development. -```sh docker run -d -p 5432:5432 \ -e POSTGRES_USER=loco \ -e POSTGRES_DB=myapp_development \ -e POSTGRES_PASSWORD="loco" \ postgres:15.3-alpine -``` @@ -58,7 +56,7 @@ docker run -d -p 5432:5432 \ Now `cd` into your `myapp` and start your app: - + ```sh $ cargo loco start diff --git a/docs-site/content/docs/getting-started/cli.md b/docs-site/content/docs/getting-started/cli.md index f72b71dfd..155229060 100644 --- a/docs-site/content/docs/getting-started/cli.md +++ b/docs-site/content/docs/getting-started/cli.md @@ -16,7 +16,7 @@ flair =[] Create your starter app: - + ```sh ❯ loco new ✔ ❯ App name? · myapp @@ -29,7 +29,7 @@ myapp Now `cd` into your app, set up a convenience `rr` alias and try out the various commands: - + ```sh cargo loco --help ``` @@ -80,7 +80,7 @@ $ cargo test To run you app, run: - + ```sh cargo loco start ``` diff --git a/docs-site/content/docs/getting-started/config.md b/docs-site/content/docs/getting-started/config.md index 2a3e3d775..ed99b1c23 100644 --- a/docs-site/content/docs/getting-started/config.md +++ b/docs-site/content/docs/getting-started/config.md @@ -61,7 +61,7 @@ config/ ``` To run the application using the 'qa' environment, execute the following command: - + ```sh LOCO_ENV=qa cargo loco start ``` diff --git a/docs-site/content/docs/getting-started/deployment.md b/docs-site/content/docs/getting-started/deployment.md index d177ede10..c8a346cce 100644 --- a/docs-site/content/docs/getting-started/deployment.md +++ b/docs-site/content/docs/getting-started/deployment.md @@ -17,7 +17,7 @@ Deployment is super simple in Loco, and this is why this guide is super short. A To deploy, build your production binary for your relevant server architecture: - + ```sh cargo build --release ``` @@ -142,7 +142,7 @@ auth: Loco offers a deployment template enabling the creation of a deployment infrastructure. - + ```sh cargo loco generate deployment ? ❯ Choose your deployment › diff --git a/docs-site/content/docs/getting-started/guide.md b/docs-site/content/docs/getting-started/guide.md index 5201e8d46..22e7df702 100644 --- a/docs-site/content/docs/getting-started/guide.md +++ b/docs-site/content/docs/getting-started/guide.md @@ -43,7 +43,7 @@ You can follow this guide for a step-by-step "bottom up" learning, or you can ju ### Installing - + ```sh cargo install loco-cli cargo install sea-orm-cli # Only when DB is needed @@ -55,7 +55,7 @@ cargo install sea-orm-cli # Only when DB is needed Now you can create your new app (choose "SaaS app" for built-in authentication). - + ```sh ❯ loco new ✔ ❯ App name? · myapp @@ -84,7 +84,7 @@ To configure a database, please run a local postgres database with loco:lo This docker command start up postgresql database server. - + ```sh docker run -d -p 5432:5432 \ -e POSTGRES_USER=loco \ @@ -102,7 +102,7 @@ docker run -p 6379:6379 -d redis redis-server Use doctor command to check the needed resources: - + ```sh $ cargo loco doctor Finished dev [unoptimized + debuginfo] target(s) in 0.32s @@ -138,7 +138,7 @@ Let's get some responses quickly. For this, we need to start up the server. ### Starting the server - + ```sh cargo loco start ``` @@ -202,7 +202,7 @@ pub fn routes() -> Routes { Start the server: - + ```sh cargo loco start ``` @@ -275,7 +275,7 @@ impl Hooks for App { That's it. Kill the server and bring it up again: - + ```sh cargo loco start ``` @@ -524,7 +524,7 @@ pub fn routes() -> Routes { Now, start the app: - + ```sh cargo loco start ``` @@ -631,7 +631,7 @@ The order of the extractors is important, as changing the order of them can lead You can now test that it works, start the app: - + ```sh cargo loco start ``` diff --git a/docs-site/content/docs/getting-started/starters.md b/docs-site/content/docs/getting-started/starters.md index 4f6bb519a..aafa59284 100644 --- a/docs-site/content/docs/getting-started/starters.md +++ b/docs-site/content/docs/getting-started/starters.md @@ -15,7 +15,7 @@ flair =[] Simplify your project setup with Loco's predefined boilerplates, designed to make your development journey smoother. To get started, install our CLI and choose the template that suits your needs. - + ```sh cargo install loco-cli cargo install sea-orm-cli # Only when DB is needed @@ -24,7 +24,7 @@ cargo install sea-orm-cli # Only when DB is needed Create a starter: - + ```sh ❯ loco new ✔ ❯ App name? · myapp diff --git a/docs-site/content/docs/getting-started/tour/index.md b/docs-site/content/docs/getting-started/tour/index.md index 074a3e8db..c906dc7ae 100644 --- a/docs-site/content/docs/getting-started/tour/index.md +++ b/docs-site/content/docs/getting-started/tour/index.md @@ -19,7 +19,7 @@ flair =[]
Let's create a blog backend on `loco` in 4 commands. First install `loco-cli` and `sea-orm-cli`: - + ```sh cargo install loco-cli cargo install sea-orm-cli # Only when DB is needed @@ -52,7 +52,7 @@ cargo install sea-orm-cli # Only when DB is needed name in the `test.yaml`configuration will be `myapp_test`, and in the `development.yaml` configuration, it will be `myapp_development`. - + ```sh docker run -d -p 5432:5432 \ -e POSTGRES_USER=loco \ @@ -67,7 +67,7 @@ docker run -d -p 5432:5432 \ Now `cd` into your `myapp` and start your app: - + ```sh $ cargo loco start @@ -120,7 +120,7 @@ injected: "tests/requests/mod.rs" Your database have been migrated and model, entities, and a full CRUD controller have been generated automatically. Start your app: - + ```sh $ cargo loco start @@ -176,7 +176,7 @@ To authenticate, you will need a running redis server. This docker command starts up a redis server: - + ```sh docker run -p 6379:6379 -d redis redis-server ``` @@ -184,7 +184,7 @@ docker run -p 6379:6379 -d redis redis-server Use doctor command to check the needed resources: - + ```sh $ cargo loco doctor Finished dev [unoptimized + debuginfo] target(s) in 0.32s diff --git a/snipdoc.yml b/snipdoc.yml index a21a342b8..0b5bdcebf 100644 --- a/snipdoc.yml +++ b/snipdoc.yml @@ -3,69 +3,47 @@ snippets: content: 🚂 Loco is Rust on Rails. path: ./snipdoc.yml help-command: - content: |- - ```sh - cargo loco --help - ``` + content: cargo loco --help path: ./snipdoc.yml exec-help-command: content: cd ./examples/demo && cargo loco --help path: ./snipdoc.yml build-command: - content: |- - ```sh - cargo build --release - ``` + content: cargo build --release path: ./snipdoc.yml quick-installation-command: content: |- - ```sh cargo install loco-cli cargo install sea-orm-cli # Only when DB is needed - ``` path: ./snipdoc.yml loco-cli-new-from-template: content: |- - ```sh ❯ loco new ✔ ❯ App name? · myapp ✔ ❯ What would you like to build? · SaaS app (with DB and user auth) 🚂 Loco app generated successfully in: myapp - ``` path: ./snipdoc.yml postgres-run-docker-command: content: |- - ```sh docker run -d -p 5432:5432 \ -e POSTGRES_USER=loco \ -e POSTGRES_DB=myapp_development \ -e POSTGRES_PASSWORD="loco" \ postgres:15.3-alpine - ``` path: ./snipdoc.yml redis-run-docker-command: - content: |- - ```sh - docker run -p 6379:6379 -d redis redis-server - ``` + content: docker run -p 6379:6379 -d redis redis-server path: ./snipdoc.yml starting-the-server-command: - content: |- - ```sh - cargo loco start - ``` + content: cargo loco start path: ./snipdoc.yml starting-the-server-command-with-environment-env-var: - content: |- - ```sh - LOCO_ENV=qa cargo loco start - ``` + content: LOCO_ENV=qa cargo loco start path: ./snipdoc.yml starting-the-server-command-with-output: content: |- - ```sh $ cargo loco start ▄ ▀ @@ -85,22 +63,18 @@ snippets: https://loco.rs listening on port 3000 - ``` path: ./snipdoc.yml doctor-command: content: |- - ```sh $ cargo loco doctor Finished dev [unoptimized + debuginfo] target(s) in 0.32s Running `target/debug/myapp-cli doctor` ✅ SeaORM CLI is installed ✅ DB connection: success ✅ Redis connection: success - ``` path: ./snipdoc.yml generate-deployment-command: content: |- - ```sh cargo loco generate deployment ? ❯ Choose your deployment › ❯ Docker @@ -111,5 +85,4 @@ snippets: ✔ ❯ Choose your deployment · Docker skipped (exists): "dockerfile" added: ".dockerignore" - ``` path: ./snipdoc.yml