Open coding-to-music opened 3 years ago
How to use Rust + WebAssembly to Perform Serverless Machine Learning and Data Visualization in the Cloud https://www.freecodecamp.org/news/rust-webassembly-serverless-tencent-cloud/
Here is the final application you will create by the end of this tutorial. It is completely “serverless” and incurs cost when people use it. https://www.secondstate.io/demo/2020-tencentcloud.html
The HTML and JavaScript UI can be hosted on any computer including your laptop, and the backend function to perform machine learning and SVG drawing is on Tencent Cloud Serverless. https://github.com/second-state/wasm-learning/tree/master/tencentcloud/ssvm/pca
wrangler
wrangler
is a CLI tool designed for folks who are interested in using Cloudflare Workers.demo-gif
Installation
You have many options to install wrangler!
Install with
npm
We strongly recommend you install
npm
with a Node version manager likenvm
, which puts the globalnode_modules
in your home directory to eliminate permissions issues withnpm install -g
. Distribution-packagednpm
installs often use/usr/lib/node_modules
(which is root) for globally installednpm
packages, and runningnpm install -g
asroot
preventswrangler
from installing properly.Once you've installed
nvm
and configured your system to use thenvm
managed node install, run:If you are running an ARM based system (eg Raspberry Pi, Pinebook) you'll need to use the
cargo
installation method listed below to build wrangler from source.Specify binary location
In case you need
wrangler
's npm installer to place the binary in a non-default location (such as when usingwrangler
in CI), you can use the following configuration options to specify an install location:WRANGLER_INSTALL_PATH
wrangler_install_path
Specify binary site URL
In case you need to store/mirror binaries on premise you will need to specify where wrangler should search for them by providing any of the following:
WRANGLER_BINARY_HOST
wrangler_binary_host
Install with
cargo
If you don't have
cargo
ornpm
installed, you will need to follow these additional instructions.Install on Windows
perl is an external dependency of crate openssl-sys. If installing wrangler with cargo, you will need to have perl installed. We've tested with Strawberry Perl. If you instead install perl via scoop, you may need to also run
scoop install openssl
in order to get the necessary openssl dlls. Installing wrangler withnpm
instead of cargo is another option if you don't want to install perl.Updating
For information regarding updating Wrangler, click here.
Getting Started
Once you have installed Wrangler, spinning up and deploying your first Worker is easy!
🎙️ Top Level Commands
👯
generate
Scaffold a project, including boilerplate code for a Rust library and a Cloudflare Worker.
All of the arguments and flags to this command are optional:
name
: defaults toworker
template
: defaults to thehttps://github.com/cloudflare/worker-template
type
: defaults tojavascript
based on the "worker-template"📥
init
Creates a skeleton
wrangler.toml
in an existing directory. This can be used as an alternative togenerate
if you prefer to clone a repository yourself.All of the arguments and flags to this command are optional:
name
: defaults to the name of your working directorytype
: defaults to "webpack".🦀⚙️
build
Build your project. This command looks at your
wrangler.toml
file and runs the build steps associated with the"type"
declared there.Additionally, you can configure different environments.
🔓
login
Authenticate Wrangler with your Cloudflare login. This will prompt you with a Cloudflare account login page and is the alternative to
wrangler config
.🔧
config
Authenticate Wrangler with a Cloudflare API Token. This is an interactive command that will prompt you for your API token:
You can also provide your email and global API key (this is not recommended for security reasons):
You can also use environment variables to configure these values.
☁️ 🆙
publish
Publish your Worker to Cloudflare. Several keys in your
wrangler.toml
determine whether you are publishing to a workers.dev subdomain or your own registered domain, proxied through Cloudflare.Additionally, you can configure different environments.
You can also use environment variables to handle authentication when you publish a Worker.
🗂
kv
Interact with your Workers KV store. This is actually a whole suite of subcommands. Read more about in Wrangler KV Documentation.
👂
dev
wrangler dev
works very similarly towrangler preview
except that instead of opening your browser to preview your worker, it will start a server on localhost that will execute your worker on incoming HTTP requests. From there you can use cURL, Postman, your browser, or any other HTTP client to test the behavior of your worker before publishing it.You should run wrangler dev from your worker directory, and if your worker makes any requests to a backend, you should specify the host with
--host example.com
.From here you should be able to send HTTP requests to
localhost:8787
along with any headers and paths, and your worker should execute as expected. Additionally, you should see console.log messages and exceptions appearing in your terminal.All of the arguments and flags to this command are optional:
env
: environment to buildhost
: domain to test behind your worker. defaults to example.comip
: ip to listen on. defaults to localhostport
: port to listen on. defaults to 8787Additional Documentation
All information regarding wrangler or Cloudflare Workers is located in the Cloudflare Workers Developer Docs. This includes:
✨Workers Sites
To learn about deploying static assets using
wrangler
, see the Workers Sites Quickstart.