Skip to content

Commit

Permalink
Merge branch 'master' into fuzzy-cli-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jondot authored Oct 18, 2024
2 parents c31a5be + 1201504 commit e35f383
Show file tree
Hide file tree
Showing 79 changed files with 972 additions and 581 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
todo.txt
examples/demo2
*.sqlite
*.sqlite-wal
*.sqlite-shm

# IDE config files
.idea
Expand Down
20 changes: 20 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,26 @@

## Unreleased


## v0.11.0


* Upgrade **SeaORM to v1.1.0**
* Added OpenAPI example
* Improve health route [https://github.com/loco-rs/loco/pull/851](https://github.com/loco-rs/loco/pull/851)
* Add good pragmas to Sqlite [https://github.com/loco-rs/loco/pull/848](https://github.com/loco-rs/loco/pull/848)
* Upgrade to rsbuild 1.0. [https://github.com/loco-rs/loco/pull/792](https://github.com/loco-rs/loco/pull/792)
* Implements fmt::Debug to pub structs. [https://github.com/loco-rs/loco/pull/812](https://github.com/loco-rs/loco/pull/812)
* Add num_workers config for sidekiq queue. [https://github.com/loco-rs/loco/pull/823](https://github.com/loco-rs/loco/pull/823)
* Fix some comments in the starters and example code. [https://github.com/loco-rs/loco/pull/824](https://github.com/loco-rs/loco/pull/824)
* Fix Y2038 bug for JWT on 32 bit platforms. [https://github.com/loco-rs/loco/pull/825](https://github.com/loco-rs/loco/pull/825)
* Make App URL in Boot Banner Clickable. [https://github.com/loco-rs/loco/pull/826](https://github.com/loco-rs/loco/pull/826)
* Add `--no-banner` flag to allow disabling the banner display. [https://github.com/loco-rs/loco/pull/839](https://github.com/loco-rs/loco/pull/839)
* add on_shutdown hook. [https://github.com/loco-rs/loco/pull/842](https://github.com/loco-rs/loco/pull/842)


## v0.10.1

* `Format(respond_to): Format` extractor in controller can now be replaced with `respond_to: RespondTo` extractor for less typing.
* When supplying data to views, you can now use `data!` instead of `serde_json::json!` for shorthand.
* Refactor middlewares. [https://github.com/loco-rs/loco/pull/785](https://github.com/loco-rs/loco/pull/785). Middleware selection, configuration, and tweaking is MUCH more powerful and convenient now. You can keep the `middleware:` section empty or remove it now, see more in [the middleware docs](https://loco.rs/docs/the-app/controller/#middleware)
Expand Down
52 changes: 26 additions & 26 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ license = "Apache-2.0"

[package]
name = "loco-rs"
version = "0.10.1"
version = "0.11.0"
description = "The one-person framework for Rust"
homepage = "https://loco.rs/"
documentation = "https://docs.rs/loco-rs"
Expand Down Expand Up @@ -47,10 +47,10 @@ colored = "2"


sea-orm = { version = "1.0.0", features = [
"sqlx-postgres", # `DATABASE_DRIVER` feature
"sqlx-sqlite",
"runtime-tokio-rustls",
"macros",
"sqlx-postgres", # `DATABASE_DRIVER` feature
"sqlx-sqlite",
"runtime-tokio-rustls",
"macros",
], optional = true }

tokio = { version = "1.33.0", default-features = false }
Expand All @@ -73,10 +73,10 @@ fs-err = "2.11.0"
tera = "1.19.1"
heck = "0.4.0"
lettre = { version = "0.11.4", default-features = false, features = [
"builder",
"hostname",
"smtp-transport",
"tokio1-rustls-tls",
"builder",
"hostname",
"smtp-transport",
"tokio1-rustls-tls",
] }
include_dir = "0.7.3"
thiserror = "1"
Expand Down Expand Up @@ -128,40 +128,40 @@ tokio-cron-scheduler = { version = "0.11.0", features = ["signal"] }
english-to-cron = { version = "0.1.2" }

# bg_pg: postgres workers
sqlx = { version = "0.7", default-features = false, features = [
"postgres",
sqlx = { version = "0.8.2", default-features = false, features = [
"postgres",
], optional = true }
ulid = { version = "1", optional = true }

# bg_redis: redis workers
rusty-sidekiq = { version = "0.8.2", default-features = false, optional = true }
rusty-sidekiq = { version = "0.11.0", default-features = false, optional = true }
bb8 = { version = "0.8.1", optional = true }

[workspace.dependencies]
async-trait = { version = "0.1.74" }
axum = { version = "0.7.5", features = ["macros"] }
tower = "0.4"
tower-http = { version = "0.6.1", features = [
"trace",
"catch-panic",
"timeout",
"add-extension",
"cors",
"fs",
"set-header",
"compression-full",
"trace",
"catch-panic",
"timeout",
"add-extension",
"cors",
"fs",
"set-header",
"compression-full",
] }

[dependencies.sea-orm-migration]
optional = true
version = "1.0.0"
features = [
# Enable at least one `ASYNC_RUNTIME` and `DATABASE_DRIVER` feature if you want to run migration via CLI.
# View the list of supported features at https://www.sea-ql.org/SeaORM/docs/install-and-config/database-and-async-runtime.
# e.g.
"runtime-tokio-rustls", # `ASYNC_RUNTIME` feature
"sqlx-postgres", # `DATABASE_DRIVER` feature
"sqlx-sqlite",
# Enable at least one `ASYNC_RUNTIME` and `DATABASE_DRIVER` feature if you want to run migration via CLI.
# View the list of supported features at https://www.sea-ql.org/SeaORM/docs/install-and-config/database-and-async-runtime.
# e.g.
"runtime-tokio-rustls", # `ASYNC_RUNTIME` feature
"sqlx-postgres", # `DATABASE_DRIVER` feature
"sqlx-sqlite",
]

[package.metadata.docs.rs]
Expand Down
3 changes: 0 additions & 3 deletions docs-site/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,6 @@ impl Model {
).await?;
}
}
```
'''

Expand Down
4 changes: 2 additions & 2 deletions docs-site/content/blog/axum-session.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ impl Hooks for App {
Now, you can create your controller that uses Axum session. Use the `cargo loco generate controller` command:

```sh
❯ cargo loco generate controller mysession -k api
❯ cargo loco generate controller mysession --api
Finished dev [unoptimized + debuginfo] target(s) in 0.36s
Running `target/debug/axum-session-cli generate controller mysession`
added: "src/controllers/mysession.rs"
Expand Down Expand Up @@ -166,7 +166,7 @@ impl Hooks for App {
Create the controller as before using `cargo loco generate controller`

```sh
❯ cargo loco generate controller mysession -k api
❯ cargo loco generate controller mysession --api
Finished dev [unoptimized + debuginfo] target(s) in 0.36s
Running `target/debug/axum-session-cli generate controller mysession`
added: "src/controllers/mysession.rs"
Expand Down
10 changes: 5 additions & 5 deletions docs-site/content/docs/getting-started/guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ Loco is a Web or API framework for Rust. It's also a productivity suite for deve

## Creating a New Loco App

You can follow this guide for a step-by-step "bottom up" learning, or you can jump and go with the [tour](./tour.md) instead for a quicker "top down" intro.
You can follow this guide for a step-by-step "bottom up" learning, or you can jump and go with the [tour](@/docs/getting-started/tour/index.md) instead for a quicker "top down" intro.

### Installing

Expand Down Expand Up @@ -131,15 +131,15 @@ $ curl localhost:5150/_health
```

<div class="infobox">
The built in <code>_health</code> route will tell you that you have configured your app properly: it can establish a connection to your Postgres and Redis instances successfully.
The built in <code>_health</code> route will tell you that you have configured your app properly: it can establish a connection to your Database and Redis instances successfully.
</div>

### Say "Hello", Loco

Let's add a quick _hello_ response to our service.

```sh
$ cargo loco generate controller guide -k api
$ cargo loco generate controller guide --api
added: "src/controllers/guide.rs"
injected: "src/controllers/mod.rs"
injected: "src/app.rs"
Expand Down Expand Up @@ -465,7 +465,7 @@ $ cargo playground
We're now ready to plug this into an `articles` controller. First, generate a new controller:
```sh
$ cargo loco generate controller articles -k api
$ cargo loco generate controller articles --api
added: "src/controllers/articles.rs"
injected: "src/controllers/mod.rs"
injected: "src/app.rs"
Expand Down Expand Up @@ -630,7 +630,7 @@ Let's add another model, this time: `Comment`. We want to create a relation - a
Instead of coding the model and controller by hand, we're going to create a **comment scaffold** which will generate a fully working CRUD API comments. We're also going to use the special `references` type:
```sh
$ cargo loco generate scaffold comment content:text article:references -k api
$ cargo loco generate scaffold comment content:text article:references --api
```
If you peek into the new migration, you'll discover a new database relation in the articles table:
Expand Down
31 changes: 26 additions & 5 deletions docs-site/content/docs/getting-started/tour/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ top = false
flair =[]
+++


<img style="width:100%; max-width:640px" src="tour.png"/>
<br/>
<br/>
Expand Down Expand Up @@ -49,6 +50,12 @@ If you select all defaults, you'll have:


Now `cd` into your `myapp` and start your app by running `cargo loco start`:


<div class="infobox">

If you have the `Client` asset serving option configured, make sure you build your frontend before starting the server. This can be done by changing into the frontend directory (`cd frontend`) and running `pnpm install` and `pnpm build`.
</div>

<!-- <snip id="starting-the-server-command-with-output" inject_from="yaml" template="sh"> -->
```sh
Expand Down Expand Up @@ -76,6 +83,7 @@ listening on port 5150


<div class="infobox">

You don't have to run things through `cargo` but in development it's highly
recommended. If you build `--release`, your binary contains everything
including your code and `cargo` or Rust is not needed. </div>
Expand All @@ -84,8 +92,13 @@ listening on port 5150

We have a base SaaS app with user authentication generated for us. Let's make it a blog backend by adding a `post` and a full CRUD API using `scaffold`:

<div class="infobox">

You can choose between generating an `api`, `html` or `htmx` scaffold using the required `-k` flag.
</div>

```sh
$ cargo loco generate scaffold post title:string content:text -k api
$ cargo loco generate scaffold post title:string content:text --api

:
:
Expand Down Expand Up @@ -127,6 +140,14 @@ listening on port 5150
```
<!-- </snip> -->

<div class="infobox">

Depending on which `-k` option you chose, the steps for creating a scaffolded resource will change. With the `api` flag or the `htmx` flag you can use the below example. But with the `html` flag, it is recommended you do the post creation steps in your browser.

If you want to use `curl` to test the `html` scaffold, you will need to send your requests with the Content-Type `application/x-www-form-urlencoded` and the body as `title=Your+Title&content=Your+Content` by default. This can be changed to allow `application/json` as a `Content-Type` in the code if desired.

</div>

Next, try adding a `post` with `curl`:

```sh
Expand All @@ -147,7 +168,7 @@ For those counting -- the commands for creating a blog backend were:
1. `cargo install loco-cli`
2. `cargo install sea-orm-cli`
3. `loco new`
4. `cargo loco generate scaffold post title:string content:text -k api`
4. `cargo loco generate scaffold post title:string content:text --api`

Done! enjoy your ride with `loco` 🚂

Expand All @@ -160,7 +181,7 @@ Your generated app contains a fully working authentication suite, based on JWTs.
The `/api/auth/register` endpoint creates a new user in the database with an `email_verification_token` for account verification. A welcome email is sent to the user with a verification link.

```sh
$ curl --location '127.0.0.1:5150/api/auth/register' \
$ curl --location 'localhost:5150/api/auth/register' \
--header 'Content-Type: application/json' \
--data-raw '{
"name": "Loco user",
Expand All @@ -176,7 +197,7 @@ For security reasons, if the user is already registered, no new user is created,
After registering a new user, use the following request to log in:

```sh
$ curl --location '127.0.0.1:5150/api/auth/login' \
$ curl --location 'localhost:5150/api/auth/login' \
--header 'Content-Type: application/json' \
--data-raw '{
"email": "[email protected]",
Expand All @@ -203,7 +224,7 @@ In your client-side app, you save this JWT token and make following requests wit
This endpoint is protected by auth middleware. We will use the token we got earlier to perform a request with the _bearer token_ technique (replace `TOKEN` with the JWT token you got earlier):

```sh
$ curl --location --request GET '127.0.0.1:5150/api/user/current' \
$ curl --location --request GET 'localhost:5150/api/user/current' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer TOKEN'
```
Expand Down
4 changes: 2 additions & 2 deletions docs-site/content/docs/processing/scheduler.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ flair =[]
+++


Loco simplifies the traditional, often cumbersome `crontab` system, making it easier and more elegant to schedule cron jobs. The scheduler job can execute either a shell script command or run a registered [task](./task.md).
Loco simplifies the traditional, often cumbersome `crontab` system, making it easier and more elegant to schedule cron jobs. The scheduler job can execute either a shell script command or run a registered [task](@/docs/processing/task.md).


## Setting Up
Expand Down Expand Up @@ -96,7 +96,7 @@ The scheduler configuration consists of the following elements:
```
* `shell`: by default `false` meaning executing the the `run` value as a task. if `true` execute the `run` value as shell command
* `run`: Cronjob command to run.
* `Task:` The task name (with variables e.x `[TASK_NAME] KEY:VAl`. follow [here](./task.md) to see task arguments ). Note that the `shell` field should be false.
* `Task:` The task name (with variables e.x `[TASK_NAME] KEY:VAl`. follow [here](@/docs/processing/task.md) to see task arguments ). Note that the `shell` field should be false.
* `Shell`: Run a shell command (e.x `"echo loco >> ./scheduler.txt"`). Note that the `shell` field should be true.
* `tags` (Optional): A list of tags to categorize and manage the job.
* `output` (Optional): Overrides the global `scheduler.output` for this job.
Expand Down
43 changes: 43 additions & 0 deletions docs-site/content/docs/resources/around-the-web.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
+++
title = "Around the Web"
description = ""
date = 2024-01-21T19:00:00+00:00
updated = 2024-01-21T19:00:00+00:00
draft = false
weight = 1
sort_by = "weight"
template = "docs/page.html"

[extra]
lead = ""
toc = true
top = false
flair =[]
+++


Check out Loco resources and links from around the Web.


## Blogs

- [Introducing Loco: the "Rust on Rails"](https://blog.rng0.io/introducing-loco/) - by [@jondot](https://x.com/jondot)
- [Loco is a New Framework for Rust Inspired by Rails](https://www.infoq.com/news/2024/02/loco-new-framework-rust-rails/) - by [infoq.com](https://infoq.com)
- [Going in cold inside the locomotive](https://vanhalt.com/post/loco-rs/) by [@vanhalt](https://twitter.com/vanhalt)
- [Introducing Loco: The Rails of Rust](https://www.shuttle.dev/blog/2023/12/20/loco-rust-rails) by [shuttle](https://shuttle.dev)
- [Getting Started with Loco & SeaORM](https://www.sea-ql.org/blog/2024-05-28-getting-started-with-loco-seaorm/) by [Billy Chan (SeaORM)](https://github.com/billy1624)

## Videos

- [A Legendary Web Framework is Reborn... in Rust](https://www.youtube.com/watch?v=7utPutDORb4) - by [Code to the Moon](https://www.youtube.com/@codetothemoon)


## Ecosystem

- [rhai-loco](https://docs.rs/rhai-loco/latest/rhai_loco/) - This crate adds [Rhai](https://rhai.rs) script support to [Loco](https://loco.rs)
- [loco-oauth2](https://github.com/yinho999/loco-oauth2) - Loco OAuth2 is a simple OAuth2 initializer for the Loco API. It is designed to be a tiny and easy-to-use library for implementing OAuth2 in your application.

## App Examples

* [Chat rooms](https://github.com/loco-rs/chat-rooms) - With opening a web socket
* [Todo list](https://github.com/loco-rs/todo-list) - working with rest API
2 changes: 1 addition & 1 deletion docs-site/content/docs/resources/faq.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ description = "Answers to frequently asked questions."
date = 2021-05-01T19:30:00+00:00
updated = 2021-05-01T19:30:00+00:00
draft = false
weight = 1
weight = 2
sort_by = "weight"
template = "docs/page.html"

Expand Down
23 changes: 0 additions & 23 deletions docs-site/content/docs/resources/live-examples.md

This file was deleted.

Loading

0 comments on commit e35f383

Please sign in to comment.