Skip to content

Commit

Permalink
Add hosting instructions/example for Shuttle
Browse files Browse the repository at this point in the history
  • Loading branch information
orhun committed Nov 8, 2023
1 parent 63e55e5 commit a3a1217
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 1 deletion.
4 changes: 3 additions & 1 deletion ECOSYSTEM.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ If your project isn't listed here and you would like it to be, please feel free
- [axum_session_auth](https://github.com/AscendingCreations/AxumSessionsAuth): Persistent session based user login with rights management for Axum.
- [axum-auth](https://crates.io/crates/axum-auth): High-level http auth extractors for axum.
- [axum-keycloak-auth](https://github.com/lpotthast/axum-keycloak-auth): Protect axum routes with a JWT emitted by Keycloak.
- [shuttle](https://github.com/getsynth/shuttle): A serverless platform built for Rust. Now with axum support.
- [axum-tungstenite](https://github.com/davidpdrsn/axum-tungstenite): WebSocket connections for axum directly using tungstenite
- [axum-jrpc](https://github.com/0xdeafbeef/axum-jrpc): Json-rpc extractor for axum
- [axum-tracing-opentelemetry](https://crates.io/crates/axum-tracing-opentelemetry): Middlewares and tools to integrate axum + tracing + opentelemetry
Expand All @@ -41,6 +40,7 @@ If your project isn't listed here and you would like it to be, please feel free
- [axum-prometheus](https://github.com/ptrskay3/axum-prometheus): A middleware library to collect HTTP metrics for axum applications, compatible with all [metrics.rs](https://metrics.rs) exporters.
- [axum-valid](https://github.com/gengteng/axum-valid): Extractors for data validation using validator, garde, and validify.
- [tower-sessions](https://github.com/maxcountryman/tower-sessions): Sessions as a `tower` and `axum` middleware.
- [shuttle](https://github.com/shuttle-hq/shuttle): Build & ship backends without writing any infrastructure files. Now with Axum support.

## Project showcase

Expand Down Expand Up @@ -91,6 +91,7 @@ If your project isn't listed here and you would like it to be, please feel free
- [Using Rust, Axum, PostgreSQL, and Tokio to build a Blog]
- [Introduction to axum]: YouTube playlist
- [Rust Axum Full Course]: YouTube video
- [Deploying Axum projects with Shuttle]

[axum-tutorial]: https://github.com/programatik29/axum-tutorial
[axum-tutorial-website]: https://programatik29.github.io/axum-tutorial/
Expand All @@ -100,4 +101,5 @@ If your project isn't listed here and you would like it to be, please feel free
[Using Rust, Axum, PostgreSQL, and Tokio to build a Blog]: https://spacedimp.com/blog/using-rust-axum-postgresql-and-tokio-to-build-a-blog/
[Introduction to axum]: https://www.youtube.com/playlist?list=PLrmY5pVcnuE-_CP7XZ_44HN-mDrLQV4nS
[Rust Axum Full Course]: https://www.youtube.com/watch?v=XZtlD_m59sM
[Deploying Axum projects with Shuttle]: https://docs.shuttle.rs/examples/axum
[Building a SaaS with Rust & Next.js](https://joshmo.bearblog.dev/lets-build-a-saas-with-rust/) A tutorial for combining Next.js with Rust via Axum to make a SaaS.
5 changes: 5 additions & 0 deletions axum/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,10 @@ to put everything together. Community-maintained [showcases] and [tutorials] als
See [here][ecosystem] for a list of community maintained crates and projects
built with `axum`.

## Hosting

You can host your Axum projects with using [Shuttle](https://www.shuttle.rs), see the example [here][shuttle-example].

## Contributing

🎈 Thanks for your help improving the project! We are so happy to have
Expand All @@ -147,6 +151,7 @@ additional terms or conditions.

[readme-example]: https://github.com/tokio-rs/axum/tree/main/examples/readme
[examples]: https://github.com/tokio-rs/axum/tree/main/examples
[shuttle-example]: https://github.com/tokio-rs/axum/tree/main/examples/hosting-on-shuttle
[docs]: https://docs.rs/axum
[`tower`]: https://crates.io/crates/tower
[`hyper`]: https://crates.io/crates/hyper
Expand Down
12 changes: 12 additions & 0 deletions examples/hosting-on-shuttle/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[package]
name = "example-shuttle"
version = "0.1.0"
edition = "2021"
publish = false

[dependencies]
axum = "0.6.20"
tokio = { version = "1.0", features = ["full"] }
shuttle-axum = "0.31"
shuttle-runtime = "0.31"
tracing = "0.1"
41 changes: 41 additions & 0 deletions examples/hosting-on-shuttle/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Hosting on Shuttle

<img width="300" src="https://raw.githubusercontent.com/shuttle-hq/shuttle/master/assets/logo-rectangle-transparent.png"/>

> [**Shuttle**](https://www.shuttle.rs) is a Rust-native cloud development platform that lets you deploy your Rust apps for free.
Shuttle has out-of-the-box support for Axum. You can follow these steps to run the example:

1. Install `cargo-shuttle`:

```sh
cargo install cargo-shuttle
```

2. Run the example locally:

```sh
cargo shuttle run --working-directory examples/hosting-on-shuttle
```

If you want to create a project and deploy a service:

1. Log in into Shuttle console:

```sh
cargo shuttle login
```

2. Create a project:

```sh
cargo shuttle project start
```

3. Deploy! 🚀

```sh
cargo shuttle deploy
```

Check out the complete Axum examples [here](https://github.com/shuttle-hq/shuttle-examples/tree/main/axum).
21 changes: 21 additions & 0 deletions examples/hosting-on-shuttle/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//! Run with
//!
//! ```not_rust
//! cargo shuttle run --working-directory examples/hosting-on-shuttle
//! ```
use axum::{routing::get, Router};

#[shuttle_runtime::main]
async fn main() -> shuttle_axum::ShuttleAxum {
// build our application with a route
let router = Router::new().route("/", get(hello_world));

// start the server
tracing::info!("starting the server");
Ok(router.into())
}

async fn hello_world() -> &'static str {
"Hello, world!"
}

0 comments on commit a3a1217

Please sign in to comment.