From 5f98b659029d3cf3851cbff46d4f2404d920acd2 Mon Sep 17 00:00:00 2001 From: Jef Roosens Date: Tue, 13 Apr 2021 22:35:39 +0200 Subject: [PATCH 1/4] Added lots of documentation --- Makefile | 30 ++++++++++++++++++++++++------ README.md | 16 ++++++++++++++++ 2 files changed, 40 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index fee2643..6ad1f50 100644 --- a/Makefile +++ b/Makefile @@ -1,48 +1,66 @@ all: debug .PHONY: all -# Builds +# Builds the debug release inside the Alpine container. For build caching, two +# volumes are used named `fej_build-cache` and `fej_registry-cache`. These +# images are automatically created for you if they don't exist. If you +# encounter any strange build errors, you can try removing this volumes to +# start a completely fresh build. debug: @ ./build -m dev -a run build .PHONY: debug +# Builds the release version. In contrary to the debug version, this build +# doesn't use volumes for caching, as this would require the build to happen +# during runtime instead of during the building of the image. Instead, it uses +# the new `--mount` feature from Buildkit. This does mean that only very recent +# Docker engines can build the release version (in my case, at the time of +# writing this, 20.10.5). release: @ ./build -m rel .PHONY: release +# This builds the release version, and pushes all relevant tags to my Docker +# Hub repository, namely chewingbever/fej push: @ ./build -m rel -a push .PHONY: push -# Run +# This builds the debug release, and runs it detached. The reason we detach the +# container is because Rocket has a tendency to ignore ctlr-c when inside a +# container, which gets annoying really fast. run: @ ./build -m dev -a run .PHONY: run +# As a workaround, we just have a stop command that stops the container. stop: @ docker stop -t 2 fej .PHONY: stop +# This attaches to the running container, essentially giving the same result as +# just running `cargo run` locally. logs: @ docker logs -f fej .PHONY: logs - -# Testing +# Builds the debug version, and runs the tests (but doesn't detach). test: @ ./build -m dev -a run -l -- test --no-fail-fast .PHONY: test +# Runs the cargo code formatter on your code. format: @ cargo fmt .PHONY: format +# Lints your code. This also gets run in the pre-commit hook, basically +# preventing you from committing badly-formatted code. lint: @ cargo fmt -- --check .PHONY: lint - -# Documentation +# This builds the documentation for the project, excluding the documentation. docs: @ cargo doc --no-deps .PHONY: docs diff --git a/README.md b/README.md index 3f8e6f4..1961201 100644 --- a/README.md +++ b/README.md @@ -24,3 +24,19 @@ Every module has a `routes` function that returns its route macros. ## Roadmap See [roadmap.md](roadmap.md). + +## Development + +The entire toolchain runs on Alpine inside Docker. This makes building easier, +and (hopefully) eliminates any system-specific bugs. + +A [Makefile wrapper](Makefile) is provided for ease of use. Do check it out, as +all the commands are documented for your understanding ;) + +There's also the `build` script. This script does all the "heavy" lifting. It +chooses which Dockerfile to build according to the given arguments, and +generates tags for the images (useful when pushing releases). The Makefile is +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. From 452683f4d7360c77a81e6057b9bdf83248fa6aec Mon Sep 17 00:00:00 2001 From: Jef Roosens Date: Tue, 13 Apr 2021 23:55:22 +0200 Subject: [PATCH 2/4] Added docker images link to README --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index 1961201..55d11e3 100644 --- a/README.md +++ b/README.md @@ -40,3 +40,7 @@ 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. + +## Docker images + +The images are available [here](https://hub.docker.com/r/chewingbever/fej). From 9ee542197dfe1586984f65000b096655a1df4edb Mon Sep 17 00:00:00 2001 From: Jef Roosens Date: Wed, 14 Apr 2021 00:00:29 +0200 Subject: [PATCH 3/4] Added kissanime to roadmap --- roadmap.md | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/roadmap.md b/roadmap.md index 17b0d76..f03e4b5 100644 --- a/roadmap.md +++ b/roadmap.md @@ -4,7 +4,7 @@ This file contains a listing of my current ideas/plans for this project. This could change at any minute, but it serves as a quick overview of my plans for the project. -## 1.0: Ivago +## Ivago ### Summary @@ -30,7 +30,7 @@ still collecting the same data. Furthermore, having the data available in computer-readable format opens up ways to write a custom frontend for the API (which I will be doing sometime in the near future). -## 2.0: The Curse of the Forge +## The Curse of the Forge ### Summary @@ -65,3 +65,12 @@ touch their websites or services (besides downloading the mods of course). As a bonus, I want to cache the Ivago API's calendars, considering I'll be setting up a database for this version anyways. + +## Kissanime + +I like watching anime from time to time, and I've always used Kissanime for +this. However, their sites can be quite slow, and riddled with ads from time to +time. That's why I'd like to create a high-speed wrapper that extracts all the +needed info from their sites, removing the need for the user to ever actually +visit their site. The API can just act as a fast search index, complete with +indexing of the links to the videos and everything. From 87f2659b4800a5f9040c5363718b176e4e2284df Mon Sep 17 00:00:00 2001 From: Jef Roosens Date: Wed, 14 Apr 2021 22:00:56 +0200 Subject: [PATCH 4/4] Added temporary CORS fix --- src/main.rs | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/main.rs b/src/main.rs index ad86d98..8b8edc7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,8 +3,36 @@ extern crate rocket; use fej_lib::{catchers, ivago}; +// Very temporary solution for CORS +// https://stackoverflow.com/questions/62412361/how-to-set-up-cors-or-options-for-rocket-rs +use rocket::fairing::{Fairing, Info, Kind}; +use rocket::http::Header; +use rocket::{Request, Response}; + +pub struct CORS; + +impl Fairing for CORS { + fn info(&self) -> Info { + Info { + name: "Add CORS headers to responses", + kind: Kind::Response, + } + } + + fn on_response(&self, _: &Request, response: &mut Response) { + response.set_header(Header::new("Access-Control-Allow-Origin", "*")); + response.set_header(Header::new( + "Access-Control-Allow-Methods", + "POST, GET, PATCH, OPTIONS", + )); + response.set_header(Header::new("Access-Control-Allow-Headers", "*")); + response.set_header(Header::new("Access-Control-Allow-Credentials", "true")); + } +} + fn rocket() -> rocket::Rocket { rocket::ignite() + .attach(CORS) .mount("/ivago", ivago::routes()) .register(catchers![catchers::not_found]) }