Skip to content

Commit 6f285a8

Browse files
committed
Ready to Go 🚀
1 parent 70860da commit 6f285a8

File tree

13 files changed

+588
-70
lines changed

13 files changed

+588
-70
lines changed

‎api/Cargo.lock

+100
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎api/Cargo.toml

+5
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,8 @@ actix-web = "4.9.0"
1616
scylla = "0.13.2"
1717
tokio-postgres = "0.7.11"
1818
chrono = "0.4.38"
19+
actix-web-actors = "4.2.0"
20+
actix = "0.13.0"
21+
tokio-stream = "0.1"
22+
futures-core = "0.3"
23+
actix-cors = "0.7.0"

‎api/src/main.rs

+16-10
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,28 @@
1+
use actix_cors::Cors;
12
use actix_web::{web::Data, App, HttpServer};
23
use db::connect_with_retry;
34
use scylla::Session;
4-
use std::time::Duration;
5+
use std::{sync::Arc, time::Duration};
56
use tokio_postgres::{Client, NoTls};
67

78
mod db;
89
mod routes;
910

1011
struct AppState {
11-
db: Session,
12+
db: Arc<Session>,
1213
client: Client,
1314
}
1415

1516
#[tokio::main]
1617
async fn main() -> std::io::Result<()> {
17-
let uri = "host.docker.internal:9042";
18+
let uri = "localhost:9042";
1819
let max_retries = 5;
1920
let initial_delay = Duration::from_secs(10);
2021

21-
let (client, connection) = tokio_postgres::connect(
22-
"postgres://postgres:postgres@host.docker.internal:5432/example",
23-
NoTls,
24-
)
25-
.await
26-
.unwrap();
22+
let (client, connection) =
23+
tokio_postgres::connect("postgres://postgres:postgres@localhost:5432/example", NoTls)
24+
.await
25+
.unwrap();
2726

2827
// Spawn the connection handler
2928
tokio::spawn(async move {
@@ -49,12 +48,19 @@ async fn main() -> std::io::Result<()> {
4948
println!("Successfully connected to Cassandra!");
5049

5150
let data = Data::new(AppState {
52-
db: session,
51+
db: Arc::new(session),
5352
client,
5453
});
5554

5655
HttpServer::new(move || {
56+
let cors = Cors::default()
57+
.allow_any_origin()
58+
.allow_any_method()
59+
.allow_any_header()
60+
.max_age(3600);
61+
5762
App::new()
63+
.wrap(cors)
5864
.app_data(data.clone())
5965
.service(routes::log::hello)
6066
.service(routes::log::create_log)

‎api/src/routes/log.rs

+64
Original file line numberDiff line numberDiff line change
@@ -118,3 +118,67 @@ pub async fn hello(data: web::Data<AppState>) -> String {
118118

119119
db_name
120120
}
121+
122+
// #[get("/live-logs/{channel_id}")]
123+
// async fn live_logs(
124+
// request: HttpRequest,
125+
// path: web::Path<String>,
126+
// state: web::Data<AppState>,
127+
// ) -> impl Responder {
128+
// let channel_id = path.into_inner();
129+
// let basic_auth = match request.headers().get("Authorization") {
130+
// Some(header) => header.to_str().unwrap_or(""),
131+
// None => return HttpResponse::Unauthorized().finish(),
132+
// };
133+
// let token = basic_auth.trim_start_matches("Basic ");
134+
// if !verify_token(&state.client, token, &channel_id).await {
135+
// return HttpResponse::Unauthorized().finish();
136+
// }
137+
138+
// let db = Arc::clone(&state.db);
139+
140+
// let stream = tokio_stream::wrappers::IntervalStream::new(interval(Duration::from_secs(5)))
141+
// .then(move |_| {
142+
// let db = Arc::clone(&db);
143+
// let channel_id = channel_id.clone();
144+
// async move {
145+
// let result = db.query(
146+
// "SELECT channel_id, timestamp, event_name, event_payload FROM raterlog.logs WHERE channel_id = ? ORDER BY timestamp DESC LIMIT 1",
147+
// (channel_id,)
148+
// ).await;
149+
// match result{
150+
// Ok(res) => {
151+
// let rows: Vec<Log> = res
152+
// .rows_typed::<Log>()
153+
// .unwrap()
154+
// .into_iter()
155+
// .map(|row| row.unwrap())
156+
// .collect();
157+
158+
// match res.into_typed_rows::<Log>() {
159+
// Some(mut rows) => {
160+
// if let Some(log) = rows.next() {
161+
// match log {
162+
// Ok(log) => {
163+
// let data = serde_json::to_string(&log).unwrap();
164+
// Ok(Bytes::from(format!("data: {}\n\n", data)))
165+
// },
166+
// Err(e) => Err(Error::from(e))
167+
// }
168+
// } else {
169+
// Ok(Bytes::from(":\n\n")) // Keep-alive when no rows
170+
// }
171+
// },
172+
// None => Ok(Bytes::from(":\n\n")) // Keep-alive when no typed rows
173+
// }
174+
// },
175+
// Err(e) => Err(Error::from(e)) // Convert database error to actix_web::Error
176+
// }
177+
// }
178+
// });
179+
180+
// HttpResponse::Ok()
181+
// .insert_header(("Content-Type", "text/event-stream"))
182+
// .insert_header(("Cache-Control", "no-cache"))
183+
// .streaming(stream)
184+
// }

‎docker-compose.yml

+8-8
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@ services:
2424
- "8001:8001"
2525
- "8444:8444"
2626

27-
# nextjs-app:
28-
# build:
29-
# context: ./web
30-
# dockerfile: Dockerfile
31-
# environment:
32-
# NODE_ENV: production
33-
# ports:
34-
# - "3000:3000"
27+
nextjs-app:
28+
build:
29+
context: ./web
30+
dockerfile: Dockerfile
31+
environment:
32+
NODE_ENV: production
33+
ports:
34+
- "3000:3000"
3535

3636
rust-api:
3737
restart: unless-stopped

‎rundocker.bat

-1
This file was deleted.

‎web/bun.lockb

12.6 KB
Binary file not shown.

‎web/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
"react": "^18.3.1",
2727
"react-dom": "^18.3.1",
2828
"react-hook-form": "^7.52.2",
29+
"recharts": "^2.12.7",
2930
"tailwind-merge": "^2.4.0",
3031
"tailwindcss-animate": "^1.0.7",
3132
"zod": "^3.23.8"

‎web/src/app/(auth)/layout.tsx

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
export const metadata = {
2-
title: 'Next.js',
3-
description: 'Generated by Next.js',
4-
}
5-
2+
title: "Raterlog Login",
3+
description: "",
4+
};
5+
import "@radix-ui/themes/styles.css";
66
export default function RootLayout({
77
children,
88
}: {
9-
children: React.ReactNode
9+
children: React.ReactNode;
1010
}) {
1111
return (
1212
<html lang="en">
1313
<body>{children}</body>
1414
</html>
15-
)
15+
);
1616
}

0 commit comments

Comments
 (0)