syuparn/wcgi-access-counter

wasi

Public
wasmer run syuparn/wcgi-access-counter

WCGI Access Counter

Continuous Integration WAPM

About

This is an access counter (aka hit counter) CGI written in WebAssembly.

$ curl localhost:8000
{"pageviews": 1}
$ curl localhost:8000
{"pageviews": 2}

You can call it from your websites!

website screenshot

website screenshot

Getting Started

You need Wasmer and WAPM to run the counter.

# install Wasmer
$ curl https://get.wasmer.io -sSfL | sh

# install this project via wapm
$ wapm install Syuparn/wcgi-access-counter
$ cd wapm_packages/Syuparn/wcgi-access-counter@${VERSION}

# run counter cgi
$ wasmer run-unstable --mapdir /tmp/counter:$(pwd)/counter --env SERVER_PROTOCOL=HTTP/1.1 --env SCRIPT_NAME=pageviews --env REQUEST_METHOD=GET .

Then the cgi can be called from localhost:8000.

$ curl localhost:8000
{"pageviews": 1}
$ curl localhost:8000
{"pageviews": 2}

Also, HTML files of sample pages shown above are in /frontend.

Views information is recorded in counter/counter.txt. You can reset it manually.

$ echo -n 0 > counter/counter.txt

Build from source codes

You need Rust, Cargo, and rustup.

# install wasm32-wasi target
$ rustup target add wasm32-wasi

# build wasm
$ cargo build --target=wasm32-wasi --release

# create counter file to record views
$ mkdir -p counter && echo -n 0 > counter/counter.txt

License

This project is generated from https://github.com/wasmerio/wcgi-rust-template.

This is licensed under either of

at your option.

It is recommended to always use [cargo crev][crev] to verify the trustworthiness of each of your dependencies, including this one.

Development

Lint

$ rustup component add clippy
$ cargo clippy

access counter cgi created by https://github.com/wasmerio/wcgi-rust-template


Github
More packages
Javascript WCGI handler
A PHP template for WCGI applications
A PHP Wordpress template for WCGI applications
A PHP Wordpress template for WCGI applications
आयुष झा (Ayush Jha)
आयुष झा (Ayush Jha)
आयुष झा (Ayush Jha)
आयुष झा (Ayush Jha)
A template for Rust WCGI applications
PHP website via WCGI starter package
PHP website via WCGI starter package
wasmer-tests/wcgi-always-panic website
Javascript WCGI hello world example.
WCGI server that responds with information about the request.

Making software universally accessible