[#26] Moved lib & bin to own folders; Moved server tests; wrote some readmes
parent
4b51ee20ca
commit
45c4a4e257
11
Cargo.toml
11
Cargo.toml
|
@ -6,7 +6,7 @@ edition = "2018"
|
||||||
|
|
||||||
[lib]
|
[lib]
|
||||||
name = "fej"
|
name = "fej"
|
||||||
src = "src/lib.rs"
|
path = "src/fej/lib.rs"
|
||||||
test = true
|
test = true
|
||||||
bench = true
|
bench = true
|
||||||
doc = true
|
doc = true
|
||||||
|
@ -14,10 +14,11 @@ doctest = true
|
||||||
|
|
||||||
[[bin]]
|
[[bin]]
|
||||||
name = "server"
|
name = "server"
|
||||||
src = "src/bin/server/main.rs"
|
path = "src/server/main.rs"
|
||||||
test = false
|
test = true
|
||||||
bench = false
|
bench = true
|
||||||
doc = false
|
doc = true
|
||||||
|
doctest = true
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
rocket = "0.4.7"
|
rocket = "0.4.7"
|
||||||
|
|
60
README.md
60
README.md
|
@ -1,25 +1,21 @@
|
||||||
# Fej
|
# Fej
|
||||||
|
|
||||||
Fej is an API written in Rust. I started this project to learn the language,
|
Fej is a RESTful API that does lots of different things. It started as an
|
||||||
and really just have some fun.
|
experiment to learn Rust, but has grown into a full-on passion project.
|
||||||
|
|
||||||
## Project Structure
|
## Project Structure
|
||||||
|
|
||||||
The folder structure follows the structure of the URLs, e.g. the route for
|
The bulk of the project consists of the main `fej` library. The `src` folder
|
||||||
`/hello/world` is found in the module `src/hello`.
|
contains the `lib.rs` file for this library, and all other binaries import from
|
||||||
|
this main library.
|
||||||
|
|
||||||
Each module contains the following base files:
|
All binaries can be found in [`/src/bin`](src/bin), with the biggest one being
|
||||||
|
`server`. This is what actually runs as the Rocket.rs server. The other
|
||||||
|
binaries (with more possibly coming) are utility tools that will most likely be
|
||||||
|
run as cron jobs inside the containers, e.g. scrapers.
|
||||||
|
|
||||||
* `mod.rs`: defines the modules' content, and contains the route definitions.
|
Version 1.1 also introduces the use of a database, namely
|
||||||
The route functions themselves only contain the functionality needed to
|
[PostgreSQL 13](https://www.postgresql.org/).
|
||||||
represent the data, not acquire it.
|
|
||||||
* `controller.rs`: this file contains the actual logic of each route. If the
|
|
||||||
logic becomes too complicated to be contained inside a single file,
|
|
||||||
`controller.rs` becomes its own module folder named `controller`.
|
|
||||||
* `tests.rs`: this contains tests for the specific module. This can also be a
|
|
||||||
module directory if need be.
|
|
||||||
|
|
||||||
Every module has a `routes` function that returns its route macros.
|
|
||||||
|
|
||||||
## Roadmap
|
## Roadmap
|
||||||
|
|
||||||
|
@ -27,19 +23,33 @@ See [roadmap.md](roadmap.md).
|
||||||
|
|
||||||
## Development
|
## Development
|
||||||
|
|
||||||
The entire toolchain runs on Alpine inside Docker. This makes building easier,
|
To make development more consistent (and keep my computer a bit cleaner) I've
|
||||||
and (hopefully) eliminates any system-specific bugs.
|
decided to run the entire toolchain using Docker, with Alpine Linux base
|
||||||
|
images. This also allows me to make really small final images. Technically,
|
||||||
|
Docker is the only dependency you need to contribute to this project
|
||||||
|
(not accounting for language servers etc.).
|
||||||
|
|
||||||
A [Makefile wrapper](Makefile) is provided for ease of use. Do check it out, as
|
A [Bash script](fejctl) is provided to speed up development on the various
|
||||||
all the commands are documented for your understanding ;)
|
binaries. It aids in starting up the containers, choosing which binary to run
|
||||||
|
etc. A quick rundown of its most important features:
|
||||||
|
|
||||||
There's also the `build` script. This script does all the "heavy" lifting. It
|
```bash
|
||||||
chooses which Dockerfile to build according to the given arguments, and
|
# By default, it compiles the 'server' binary (but doesn't run it)
|
||||||
generates tags for the images (useful when pushing releases). The Makefile is
|
./fejctl
|
||||||
really just a wrapper around this build script, allowing you to write
|
|
||||||
`make test` instead of `./build -m dev -a run test`.
|
|
||||||
|
|
||||||
tl;dr run `make run` to run your build, and `make test` to run the tests.
|
# The first argument is the action you wish to perform, the second on which
|
||||||
|
# binary (not all commands need a binary as input, so they just ignore it)
|
||||||
|
# For example, this will run the binary called server
|
||||||
|
./fejctl r server
|
||||||
|
|
||||||
|
# This runs the tests (all commands also have their full name if you want)
|
||||||
|
./fejctl t
|
||||||
|
./fejctl test
|
||||||
|
|
||||||
|
# These attach to the two containers
|
||||||
|
./fejctl sh # Opens a new root shell inside the 'fej' container
|
||||||
|
./fejctl psql # Open a new psql shell in the fej database
|
||||||
|
```
|
||||||
|
|
||||||
## Docker images
|
## Docker images
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,10 @@
|
||||||
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate rocket;
|
extern crate rocket;
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests;
|
||||||
|
|
||||||
mod catchers;
|
mod catchers;
|
||||||
mod routes;
|
mod routes;
|
||||||
|
|
|
@ -3,7 +3,7 @@ use rocket::http::Status;
|
||||||
use rocket::local::Client;
|
use rocket::local::Client;
|
||||||
|
|
||||||
fn rocket() -> rocket::Rocket {
|
fn rocket() -> rocket::Rocket {
|
||||||
rocket::ignite().mount("/", fej_lib::ivago::routes())
|
rocket::ignite().mount("/", super::routes::ivago())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Test 404 response
|
/// Test 404 response
|
Loading…
Reference in New Issue