Code Monkey home page Code Monkey logo

start-axum-0.7's Introduction

Leptos Logo

Leptos Axum Starter Template

This is a template for use with the Leptos web framework and the cargo-leptos tool using Axum.

Creating your template repo

If you don't have cargo-leptos installed you can install it with

cargo install cargo-leptos --locked

Then run

cargo leptos new --git https://github.com/leptos-rs/start-axum-0.7

to generate a new project template.

cd {{project-name}}

to go to your newly created project.
Feel free to explore the project structure, but the best place to start with your application code is in src/app.rs.
Addtionally, Cargo.toml may need updating as new versions of the dependencies are released, especially if things are not working after a cargo update.

Running your project

cargo leptos watch

Installing Additional Tools

By default, cargo-leptos uses nightly Rust, cargo-generate, and sass. If you run into any trouble, you may need to install one or more of these tools.

  1. rustup toolchain install nightly --allow-downgrade - make sure you have Rust nightly
  2. rustup target add wasm32-unknown-unknown - add the ability to compile Rust to WebAssembly
  3. cargo install cargo-generate - install cargo-generate binary (should be installed automatically in future)
  4. npm install -g sass - install dart-sass (should be optional in future
  5. Run npm install in end2end subdirectory before test

Compiling for Release

cargo leptos build --release

Will generate your server binary in target/server/release and your site package in target/site

Testing Your Project

cargo leptos end-to-end
cargo leptos end-to-end --release

Cargo-leptos uses Playwright as the end-to-end test tool.
Tests are located in end2end/tests directory.

Executing a Server on a Remote Machine Without the Toolchain

After running a cargo leptos build --release the minimum files needed are:

  1. The server binary located in target/server/release
  2. The site directory and all files within located in target/site

Copy these files to your remote server. The directory structure should be:

{{project-name}}
site/

Set the following environment variables (updating for your project as needed):

export LEPTOS_OUTPUT_NAME="{{project-name}}"
export LEPTOS_SITE_ROOT="site"
export LEPTOS_SITE_PKG_DIR="pkg"
export LEPTOS_SITE_ADDR="127.0.0.1:3000"
export LEPTOS_RELOAD_PORT="3001"

Finally, run the server binary.

Licensing

This template itself is released under the Unlicense. You should replace the LICENSE for your own application with an appropriate license if you plan to release it publicly.

start-axum-0.7's People

Contributors

gbj avatar dlintw avatar mondeja avatar yatesco avatar farrej10 avatar dmgolembiowski avatar jaskij avatar

Stargazers

Matin Mohammadi avatar Valera avatar Douglas Harcourt Parsons avatar Kyle L. Davis avatar GuillaumeFortin avatar Paweł Pyrek avatar David avatar  avatar Bendegúz Török avatar  avatar Daniil Trotsenko avatar ghosty avatar rust avatar Dominik Wilkowski avatar 椰格 avatar Sawyer Bristol avatar Christoph Grabo avatar Javier E. avatar Yfy Dev avatar InvMor avatar Andrejs Agejevs avatar  avatar Dusty Pomerleau avatar Victor Ferreira da Silva avatar Erlang Parasu avatar Snêu avatar Dennis Jensen avatar

Watchers

Tumas avatar  avatar Ben Wishovich avatar

start-axum-0.7's Issues

when I change the lib name, build --release cannot find the `project.wasm` file

it raise up an error when run cargo leptos watch

warning: output filename collision.
The bin target `projectname` in package `projectname v0.1.0 (D:\leptos\projectname)` has the same output filename as the lib target `projectname` in package `projectname v0.1.0 (D:\leptos\projectname)`.
Colliding filename is: D:\leptos\projectname\target\debug\deps\projectname.pdb
The targets should have unique names.
Consider changing their names to be unique or compiling them separately.
This may become a hard error in the future; see <https://github.com/rust-lang/cargo/issues/6313>.

so, i add an item in [lib] of Cargo.toml

[lib]
name = "projectname_lib" # add this line for name collision
crate-type = ["cdylib", "rlib"]

but when i ran it again, it comes up an error

Error: at `C:\Users\UserName\.cargo\registry\src\rsproxy.cn-8f6827c7555bfaf8\cargo-leptos-0.2.24\src\compile\front.rs:51:30`

Caused by:
    0: at `C:\Users\UserName\.cargo\registry\src\rsproxy.cn-8f6827c7555bfaf8\cargo-leptos-0.2.24\src\compile\front.rs:126:10`
    1: failed reading 'target\front\wasm32-unknown-unknown\wasm-release\projectname.wasm'
    2: The system cannot find the specified file. (os error 2)

then how can i fix it?
by using new lib new and modify the wasm-release file name.

Multiple errors when running a freshly generated project

New project fails to build with cargo leptos new --git https://github.com/leptos-rs/start-axum-0.7, choosing "Nightly", and then running cargo +nightly leptos watch.

Stale WASM

      Front compiling WASM
Error: at `/Users/coliny/.cargo/registry/src/index.crates.io-6f17d22bba15001f/cargo-leptos-0.2.21/src/compile/front.rs:51:30`

Caused by:
    0: at `/Users/coliny/.cargo/registry/src/index.crates.io-6f17d22bba15001f/cargo-leptos-0.2.21/src/compile/front.rs:126:10`
    1: 
       
       it looks like the Rust project used to create this Wasm file was linked against
       version of wasm-bindgen that uses a different bindgen format than this binary:
       
         rust Wasm file schema version: 0.2.93 (d6dec17c7)
            this binary schema version: 0.2.95 (d6dec17c7)
       
       Currently the bindgen format is unstable enough that these two schema versions
       must exactly match. You can accomplish this by either updating this binary or
       the wasm-bindgen dependency in the Rust project.
       
       You should be able to update the wasm-bindgen dependency with:
       
           cargo update -p wasm-bindgen --precise 0.2.95 (d6dec17c7)
       
       don't forget to recompile your Wasm file! Alternatively, you can update the
       binary with:
       
           cargo install -f wasm-bindgen-cli --version 0.2.93 (d6dec17c7)
       
       if this warning fails to go away though and you're not sure what to do feel free
       to open an issue at https://github.com/rustwasm/wasm-bindgen/issues!
       

Stack backtrace:
   0: std::backtrace::Backtrace::create
   1: std::backtrace::Backtrace::capture
   2: anyhow::error::<impl anyhow::Error>::msg
   3: anyhow::__private::format_err
   4: wasm_bindgen_cli_support::wit::extract_programs
   5: wasm_bindgen_cli_support::Bindgen::generate_output
   6: cargo_leptos::compile::front::front::{{closure}}::{{closure}}
   7: tokio::runtime::task::core::Core<T,S>::poll
   8: tokio::runtime::task::harness::Harness<T,S>::poll
   9: tokio::runtime::scheduler::multi_thread::worker::Context::run_task
  10: tokio::runtime::scheduler::multi_thread::worker::Context::run
  11: tokio::runtime::context::runtime::enter_runtime
  12: tokio::runtime::scheduler::multi_thread::worker::run
  13: <tokio::runtime::blocking::task::BlockingTask<T> as core::future::future::Future>::poll
  14: tokio::runtime::task::core::Core<T,S>::poll
  15: tokio::runtime::task::harness::Harness<T,S>::poll
  16: tokio::runtime::blocking::pool::Inner::run
  17: std::sys::backtrace::__rust_begin_short_backtrace
  18: core::ops::function::FnOnce::call_once{{vtable.shim}}
  19: std::sys::pal::unix::thread::Thread::new::thread_start
  20: __pthread_start
❯ 

Updating to the latest wasm-bindgen (0.2.95) solves this

missing use statement for log!

error: cannot find macro `log` in this scope
  --> src/main.rs:26:5
   |
26 |     log!("listening on http://{}", &addr);
   |     ^^^
   |
help: consider importing this macro
   |
2  + use leptos::logging::log;
   |

error: could not compile `abc` (bin "abc") due to 1 previous error
      Notify watching paths style, src, public

Adding the recommend use statement solves this (but I'm surprised it isn't in the prelude?)

Works, but older version

The generated Cargo.toml refers to 0.7.0-beta not 0.7.0-rc1.

NOTE: all of these issues are solved in the pull request I've just created (#4)

can not run cargo leptos watch

I just install the rustup and stable rust 1.83.0. And follow this README to do till cd hello-ssr. All works.

When I type 'cargo leptos watch', it can not compile. I found the solution is rustup target add wasm32-unknown-unknown . It is recommend install it automatically in the install process of leptos, or said before the ## Running your project section.

can not run release version by just read this README.md

I've done ## Compiling for Release.

Will generate your server binary in target/server/release and your site package in target/site .

I don't understand this. I found the release file is on target/release/hello-ssr (my project name).
or maybe the hello-ssr can combined all resourced into one binary for easier install?

My memo about this. (only for linux/mac user)

## Run Release without source code
pack in a tgz file.
tar czf {{project-name}}.tgz target/release/{{project-name}} target/site

mkdir /tmp/your_site
tar -C /tmp/your_site -xf {{project-name}}.tgz
cd /tmp/your_site
target/release/{{project-name}}

can not run `cargo leptos build --release`, hang on install wasm-opt 117

I just install the rustup and stable rust 1.83.0, cargo-leptos and rustup target add wasm32-unknown-unknown.

When I try to build by cargo leptos build --release failed.

My solution.

cargo install wasm-pack
cargo install wasm-opt

This will install wasm-opt 116, but it let the build workable.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.