8000 GitHub - Leereen/fbp
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
This repository was archived by the owner on Jan 3, 2025. It is now read-only.

Leereen/fbp

Repository files navigation

Travis Build Status

Freshly Baked Primes

Freshly Baked Primes is a very basic pet projet I started to discover the Rust programming langage, as well as and the ReactJS library.

It is a very simple HTTP API returning prime numbers. And a very simple Web application to use the API through clicks and sweet colors.

For now, it uses...

For the API:

  • Rocket for the HTTP API,
  • Primes to generate the prime numbers,
  • Diesel to manipulate the SQLite DB.

For the frontend:

How-to

API

Compile

As a pure Rust repo for now, the compilation is very simple (given you have Rust already; if not, see here):

git clone git@github.com:Leereen/fbp.git
cd fbp
cargo build

Run

Again, very simple:

cargo run

HTTP API usage

The API is composed of 4 routes accessible with the GET HTTP method. They all return a JSON with the following structure:

{
    "value":    <u64>,   // the prime number
    "position": <usize>, // the prime number position, given '1' has position '0'
                         // (then '2' is first, '3' second, '5' third, ...)
    "duration": <f64>,   // the time FBP took to generate the prime number
    "new":      <bool>   // if the prime has never been calculated by FBP
                         // (is it stored in the local DB?)
}
  • / returns a prime randomly picked from the database.
  • /first_grater_than/<N: int> returns the first prime number strictly greater than N.
  • /greater_than/<N: int> returns a prime from the database greater than N. If the database does not contain such prime, falls back to previous route.
  • /at_position/<k: int> returns the prime number at position k (given 1 has position 0).

The database grows with time, as every calculated prime is stored.

Frontend

You will need npm installed on your system. I use version 7.13.0.

Dependencies

(cd frontend && npm install)

Starting a local server

First, you must change the HOST variable in frontend/src/Globals.js to target your API URL. Then:

(cd frontend && npm start)

If your too lazy to run your own API, tweak the frontend to use it and deal with the CORS, you can use local-cors-proxy.

It is in the frontend/package.json file so it should already be available if you followed the previous "Dependencies" step. Before npm start, in another terminal, just do:

./frontend/node_modules/.bin/lcp --proxyUrl https://freshlybakedprimes.eu

I can't guarantee this URL would survive for decades, but you get the idea.

Building production bundle

Same deal than previous step: you need to change the HOST variable in frontend/src/Globals.js to target your API URL.

After that:

(cd frontend && npm run build)

You can now copy the frontend/build/ directory wherever you like and configure a HTTP server to serve it.

License

You can read the LICENSE file or trust me when I say its MIT.

0