6 Commits
Author SHA1 Message Date
nyeki 7f96eab2c4 Update git repo link in docs 2026-07-16 02:43:19 -03:00
nyeki 682ef1f285 Update README Docker instructions 2026-07-16 02:41:20 -03:00
nyeki eb94fb8e54 Move docs and healthcheck at /* to /v1 /* 2026-07-16 02:36:08 -03:00
nyeki 6f98163632 Release version v1.1.4 2026-01-07 15:26:04 -03:00
nyeki 57eeb0878c Add CORS middleware to v1 2026-01-07 15:24:10 -03:00
nyeki 245adccf23 Release version v1.1.3 2026-01-02 00:44:11 -03:00
5 changed files with 26 additions and 12 deletions
Generated
+1 -1
View File
@@ -84,7 +84,7 @@ dependencies = [
[[package]]
name = "api"
version = "1.1.2"
version = "1.1.4"
dependencies = [
"axum",
"bitcode",
+1 -1
View File
@@ -1,6 +1,6 @@
[package]
name = "api"
version = "1.1.2"
version = "1.1.4"
edition = "2024"
[dependencies]
+1 -1
View File
@@ -36,7 +36,7 @@ CLI arguments go after the `--` in the cargo command.
To run deploy the API with Docker, just run:
```sh
$ docker run registry.nyeki.dev/nyeki/api:latest -p 8000:80 \
$ docker run registry.nyeki.dev/nyeki/api:v1.1.4 -p 8000:80 \
$ -e DISCORD_TOKEN="..." \
$ -e GITHUB_TOKEN="..."
```
+4 -4
View File
@@ -9,8 +9,8 @@ pub mod v1;
pub fn router() -> Router<Arc<State>> {
Router::new()
.route("/", get(docs))
.route("/healthcheck", get(healthcheck))
.route("/v1/healthcheck", get(healthcheck))
.route("/v1/docs", get(docs))
.nest("/v1", v1::router())
}
@@ -33,7 +33,7 @@ async fn docs() -> &'static str {
The current endpoints are:
GET /healthcheck
GET /v1/healthcheck
Returns OK when the API is running.
GET /v1/profile
@@ -121,7 +121,7 @@ async fn docs() -> &'static str {
}
```
This API is open source and available at https://git.nyeki.dev/nyeki/api to self-host.
This API is open source and available at https://git.moan.dev/nyeki/nyeki-api to self-host.
Liked it? Found it useful? A donation would be appreciated! You can do so at
https://ko-fi.com/nyeki.
"
+19 -5
View File
@@ -5,7 +5,8 @@ use std::sync::Arc;
use axum::{
Json, Router,
body::{Body, Bytes},
extract::{Query, State as AxumState},
extract::{Query, Request, State as AxumState},
middleware::Next,
response::{Redirect, Response},
routing::get,
};
@@ -26,6 +27,7 @@ pub fn router() -> Router<Arc<State>> {
.route("/proxy", get(proxy_with_cors))
.fallback(error_404)
.method_not_allowed_fallback(error_405)
.layer(axum::middleware::from_fn(cors_middleware))
}
async fn error_404() -> Error {
@@ -42,6 +44,22 @@ async fn error_405() -> Error {
}
}
async fn cors_middleware(req: Request, next: Next) -> Response {
let mut response = next.run(req).await;
let headers = response.headers_mut();
// Insert CORS headers
headers.insert("access-control-allow-origin", "*".parse().unwrap());
headers.insert(
"access-control-allow-methods",
"GET, OPTIONS".parse().unwrap(),
);
headers.insert("access-control-allow-headers", "*".parse().unwrap());
response
}
#[derive(Debug, Serialize, Encode, Decode)]
struct Profile {
username: String,
@@ -336,10 +354,6 @@ async fn proxy_with_cors(Query(params): Query<ProxyQuery>) -> Result<Response, E
}
headers_mut.insert(key, value.clone());
}
// Insert CORS headers
headers_mut.insert("access-control-allow-origin", "*".parse().unwrap());
headers_mut.insert("access-control-allow-methods", "GET, OPTIONS".parse().unwrap());
headers_mut.insert("access-control-allow-headers", "*".parse().unwrap());
Ok(response.body(body).unwrap())
}