diff --git a/RUNNING.md b/RUNNING.md index f822f9e..fbc87f8 100644 --- a/RUNNING.md +++ b/RUNNING.md @@ -16,6 +16,7 @@ liking. Here's a list of what they are: - `bind_host` (string): What address to bind to - `bind_port` (zero or positive integer): What port to bind to - `image_proxy_url` (string): URL to proxy images to (see https://pixiv.cat/reverseproxy.html), a trailing slash is not needed +- `canonical_origin` (string or null): A fallback canonical origin if set, useful if you're, say, running Pixwhile behind Ngrok Pixwhile is intended to be run behind a reverse proxy (e.g. Nginx), so you should set your reverse proxy to proxy requests to diff --git a/config.cpp b/config.cpp index c136e33..92c016d 100644 --- a/config.cpp +++ b/config.cpp @@ -17,4 +17,7 @@ void from_json(const nlohmann::json& j, Config& config) { throw std::invalid_argument("Invalid port to bind to: "s + std::to_string(config.bind_port)); } config.image_proxy_url = j.at("image_proxy_url").get(); + if (j.contains("canonical_origin") && j["canonical_origin"].is_string()) { + config.canonical_origin = j["canonical_origin"].get(); + } } diff --git a/config.h b/config.h index 25b8789..7f46d2c 100644 --- a/config.h +++ b/config.h @@ -8,6 +8,7 @@ struct Config { std::string bind_host = "127.0.0.1"; int bind_port = 8080; blankie::murl::Url image_proxy_url{"https://i.pixiv.cat"}; + std::optional canonical_origin; }; Config load_config(const char* path); diff --git a/example_config.json b/example_config.json index 6bf1cd8..f20a030 100644 --- a/example_config.json +++ b/example_config.json @@ -1,5 +1,6 @@ { "bind_host": "127.0.0.1", "bind_port": 8080, - "image_proxy_url": "https://i.pixiv.cat" + "image_proxy_url": "https://i.pixiv.cat", + "canonical_origin": null } diff --git a/servehelper.cpp b/servehelper.cpp index e199c7d..3f8007a 100644 --- a/servehelper.cpp +++ b/servehelper.cpp @@ -79,6 +79,9 @@ std::string get_origin(const httplib::Request& req, const Config& config) { if (req.has_header("X-Canonical-Origin")) { return req.get_header_value("X-Canonical-Origin"); } + if (config.canonical_origin) { + return *config.canonical_origin; + } std::string origin = "http://"; if (req.has_header("Host")) {