Code Monkey home page Code Monkey logo

resource-aggregator's Introduction

Rocket Resource Aggregator

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.

Demo video

target.mp4

Server quick start

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.

Dependencies

  • Docker
  • docker-compose
  • rustc >= 1.52.1
  • sqlx CLI

Set up a database

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

Start the server

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

Frontend quick start

Dependencies

  • node (latest or an active LTS version)
  • Angular CLI (Angular 12)

Serve the files

cd public
ng serve

Example APIs

Get all resources

curl http://localhost:8000/resource

Create a new 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"}'

Update an existing resource

# 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"}}'

Delete a resource

curl http://localhost:8000/resource \
  -X DELETE \
  -H 'Content-Type: application/json' \
  --data '{"name":"hello"}'

Build

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.

Dependencies

Building depends on both the server and front-end dependencies.

Commands

# 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'

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.