This commit is contained in:
Tony Rewin 2023-10-06 13:50:20 +03:00
parent c24fee0011
commit 12dd58c566
5 changed files with 14 additions and 12 deletions

View File

@ -15,5 +15,5 @@ reqwest = { version = "0.11", features = ["json"] }
futures = "0.3.28" futures = "0.3.28"
[[bin]] [[bin]]
name = "presense" name = "presence"
path = "./src/main.rs" path = "./src/main.rs"

View File

@ -5,8 +5,8 @@ RUN apt-get update -y && \
apt-get install -y git pkg-config make g++ libssl-dev wget && \ apt-get install -y git pkg-config make g++ libssl-dev wget && \
rustup target add x86_64-unknown-linux-gnu rustup target add x86_64-unknown-linux-gnu
RUN USER=root cargo new --bin presense RUN USER=root cargo new --bin presence
WORKDIR /presense WORKDIR /presence
COPY ./Cargo.lock ./Cargo.lock COPY ./Cargo.lock ./Cargo.lock
COPY ./Cargo.toml ./Cargo.toml COPY ./Cargo.toml ./Cargo.toml
@ -20,7 +20,7 @@ RUN rm src/*.rs
COPY ./src ./src COPY ./src ./src
# build for release # build for release
RUN rm ./target/release/deps/presense* RUN rm ./target/release/deps/presence*
RUN cargo build --release RUN cargo build --release
FROM rustlang/rust:nightly-slim FROM rustlang/rust:nightly-slim
@ -28,5 +28,5 @@ FROM rustlang/rust:nightly-slim
ENV RUST_BACKTRACE=full ENV RUST_BACKTRACE=full
RUN apt-get update && apt install -y openssl libssl-dev RUN apt-get update && apt install -y openssl libssl-dev
COPY --from=build /presense/target/release/presense . COPY --from=build /presence/target/release/presence .
CMD ["./presense"] CMD ["./presence"]

View File

@ -6,6 +6,7 @@
### ENV ### ENV
- API_BASE - API_BASE
- AUTH_URL
- REDIS_URL - REDIS_URL

View File

@ -5,14 +5,14 @@ use std::error::Error;
use std::env; use std::env;
pub async fn get_auth_id(token: &str) -> Result<i32, Box<dyn Error>> { pub async fn get_auth_id(token: &str) -> Result<i32, Box<dyn Error>> {
let api_base = env::var("API_BASE")?; let auth_api_base = env::var("AUTH_URL")?;
let gql = match api_base.contains("v2") { let gql = match auth_api_base.contains("v2") {
true => r#"mutation { getSession { user { id } } }"#, // v2 true => r#"mutation { getSession { user { id } } }"#, // v2
_ => r#"query { sessiom { user { id } } }"# // authorizer _ => r#"query { sessiom { user { id } } }"# // authorizer
}; };
let client = HTTPClient::new(); let client = HTTPClient::new();
let response = client let response = client
.post(api_base) .post(auth_api_base)
.bearer_auth(token) // NOTE: auth token is here .bearer_auth(token) // NOTE: auth token is here
.body(gql) .body(gql)
.send() .send()

View File

@ -77,7 +77,8 @@ async fn main() -> std::io::Result<()> {
.route("/connect", web::get().to(sse_handler)) .route("/connect", web::get().to(sse_handler))
.route("/disconnect", web::get().to(sse_handler)) .route("/disconnect", web::get().to(sse_handler))
}) })
.bind("127.0.0.1:8080")? .bind("127.0.0.1:80")?
.run() .run()
.await .await
} }