This project is a basic data aggregator for resources on a LAN.
The LAN wording is important because there are no security considerations done for the code.
The HTTP server runs on Rocket 0.5 and uses sqlx+postgresql as the database.
The client side is Angular 12.
For the most part, this is a learning project for Rocket and Angular, though it also fulfills a personal need.
target.mp4
These instructions don't serve the client-side files — only the server APIs
which will allow CORS requests from the default Angular ng serve
address.
To serve client-side files, see the front-end and build sections.
- Docker
- docker-compose
- rustc
>= 1.52.1
- sqlx CLI
There is a docker-compose.yml file that can be used to quickly set up a postgres docker container. Run the command below from the root folder of the git repository:
docker-compose up -d
Use the commands below to start the Rocket HTTP server:
export DATABASE_URL=postgres://default@localhost:6000
export PGPASSWORD=default
export SQLX_OFFLINE=true
cargo run --features dev_cors
- node (latest or an active LTS version)
- Angular CLI (Angular 12)
cd public
ng serve
curl http://localhost:8000/resource
# The fields `name` and `description` are required
curl http://localhost:8000/resource/new \
-X POST \
-H 'Content-Type: application/json' \
--data '{"name":"hello","description":"hello world"}'
# all fields except `name` are optional
curl http://localhost:8000/resource \
-X POST \
-H 'Content-Type: application/json' \
--data '{"name":"hello","description":"this is a useful description"}'
curl http://localhost:8000/resource \
-X POST \
-H 'Content-Type: application/json' \
--data '{"name":"hello","status":"unused"}'
curl http://localhost:8000/resource \
-X POST \
-H 'Content-Type: application/json' \
--data '{"name":"hello","other_fields":{"hi":"hello"}}'
curl http://localhost:8000/resource \
-X DELETE \
-H 'Content-Type: application/json' \
--data '{"name":"hello"}'
These are the instructions to generate a .tar.gz
file containing all that is
needed to run the application on another device. The other device needs to have
docker and docker-compose installed.
Building depends on both the server and front-end dependencies.
# create the archive
bash build.sh
# move the bundle
rsync -avz resource-aggregator.tar.gz my_ssh_alias:~
# ssh into the other device.
ssh my_ssh_alias
tar xf resource-aggregator.tar.gz
cd resource-aggregator
docker-compose up -d
# usually need sudo to serve on port 80
sudo bash -c '
export DATABASE_URL=postgres://default@localhost:6000
export PGPASSWORD=default
export ROCKET_ADDRESS=0.0.0.0
export ROCKET_PORT=80
./server'