Coder Social home page Coder Social logo

rust-wasm's Introduction

rust-wasm

You can read Chinese document here δΈ­ζ–‡

This is a simple example of how to use Rust and WebAssembly together to build a web application.

Setup

You'll need to install Rust development tools. You can do this by running:

curl https://sh.rustup.rs -sSf | sh

Running database

cd db
docker-compose up -d

Now you can access the database at localhost:5432 with the username postgres and password postgres.

You can also access the database management tool at localhost:8081 with the username postgres and password postgres on the browser.

Running webservice and webapp

Firstly, you should set the DATABASE_URL environment variable to include the database credentials like so: postgres://postgres:postgres@localhost:5432/postgres on .env file of the project root.

Secondly, you should set the HOST_PORT environment variable to include the IP address and port of the host machine like so: http://localhost:8080 on .env file of the webapp root.

To run the webservice, you can run:

cd webservice
cargo run

Now you can open another terminal and run the webapp. To run the webapp, you can run:

cd webapp
cargo run

Running WebAssembly

To run the WebAssembly, first you need to install the wasm-pack tool:

cargo install wasm-pack

Then, you can run the following commands:

cd wasm-client
wasm-pack build

install the npm dependencies:

cd wasm-client/www
npm install

run the WebAssembly app:

npm run start

Build production

Build webservice and webapp:

cargo build --release --bin webservice
cargo build --release --bin webapp

Build WebAssembly app:

# generate WebAssembly package
cd wasm-client
wasm-pack build --release
# build webapp
cd www
npm run build

rust-wasm's People

Stargazers

 avatar  avatar

Watchers

 avatar

Forkers

unicornrust

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.