FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

bright-org/micro_scaffold_example · GitHub

Latest commit

 

History

20 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MicroScaffoldExample

A scaffold example application built on top of MicroPhoenix.

The app can run on host BEAM (mix run) or AtomVM (./bin/atomvm-run). Both use port 8080 — do not run them at the same time.

Usage

mix deps.get
mix run --no-halt

The server will start on http://localhost:8080/

Required permissions for Req/ExTCP

Req.get uses raw socket access through ExTCP.
If :eperm occurs, grant cap_net_raw to beam.smp:

ERL_ROOT=$(erl -noshell -eval 'io:format("~s",[code:root_dir()]), halt().')
sudo setcap cap_net_raw+ep "$ERL_ROOT"/erts-*/bin/beam.smp
getcap "$ERL_ROOT"/erts-*/bin/beam.smp

Expected output includes:

.../beam.smp cap_net_raw=ep

If you see _build/... permission denied, fix ownership:

sudo chown -R "$(id -un)":"$(id -gn)" _build

Create test data

Before starting the server, you can create 5 sample Items.Item records with:

mix run -e "Enum.each(MicroScaffoldExample.Seed.names(), fn name -> MicroScaffoldExample.Items.create_item(name) end)"

Requires PostgreSQL and psql. See config/config.exs for connection settings.

AtomVM

Build and run on AtomVM:

export ATOMVM_INSTALL_PREFIX=/path/to/AtomVM/build
export PATH="$ATOMVM_INSTALL_PREFIX/src:$PATH"

mkdir -p avm_deps   # must be empty
mix deps.get
mix atomvm.packbeam
./bin/atomvm-run

bin/atomvm-run loads stdlib AVMs (atomvmlib, estdlib, exavmlib) together with the app.

On AtomVM, /index2.html lists 5 seeded items (compile-time, same names as host).

/index3.html on AtomVM

Proxies http://localhost:8000/index3.html via Req.get. On AtomVM, Req uses gen_tcp (not ExTCP raw sockets). Start an upstream HTTP server on port 8000 before testing:

# example upstream (separate terminal)
python3 -m http.server 8000 --directory /path/with/index3.html

If upstream is down, /index3.html returns HTTP 502.

Host BEAM still uses ExTCP and needs cap_net_raw (see above).

Endpoints

Method Path Host BEAM AtomVM
GET /, /index.html Demo page Demo page
GET /api/status Status JSON Status JSON
GET /index2.html Items (PostgreSQL) 5 seeded items
GET /index3.html Proxied via Req (ExTCP) Proxied via Req (gen_tcp)

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages


Back | FazBrowse Home | New Git URL