A simple and minimal template for development of web applications using Next.js as a frontend and Rocket as a backend with Diesel as an ORM.
- Ensure you have the latest stable versions of rustup and Node.js installed
- Clone the repository, run
npm i
- Follow the Diesel getting started guide for configuring and setting up Diesel
For development, use npm run dev
. This starts both the Next.js development server as well as the Rocket server. There is a proxy in place for all requests to localhost:3000/api
, which goes to localhost:8000/api
. Therefore, you can simply fetch data using fetch("/api")
.
To use the database connection, simply pass the DbConn
type as a request guard to a handler. The following example uses the fictional Logs
type and is adapted from the Rocket documentation.
#[get("/logs/<id>")]
fn get_logs(conn: DbConn, id: usize) -> Logs {
logs::filter(id.eq(log_id)).load(&*conn)
}