Skip to content

Commit b183145

Browse files
committed
chore: port, redirect, cors config
1 parent 0e9fcac commit b183145

File tree

5 files changed

+30
-7
lines changed

5 files changed

+30
-7
lines changed

.env.example

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
OPENAI_API_KEY=
2-
QDRANT_URL= #Default: http://localhost:6334
3-
RUST_LOG= #Logging levels: "error", "warn", "info", "debug", "trace"
2+
QDRANT_URL= #Defaults to http://localhost:6334
3+
RUST_LOG= #Logging levels: "error", "warn", "info", "debug", "trace"
4+
WEBSERVER_PORT= #Defaults to 3000

Cargo.lock

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

Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,4 @@ actix-rt = "2"
3030
tracing-actix-web = "0.7"
3131
env_logger = "0.10"
3232
tokio = "1"
33+
actix-cors = "0.6.4"

src/constants.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ pub const EMBEDDINGS_DIMENSION: usize = 384;
55

66
//Actix-web
77
pub const SSE_CHANNEL_BUFFER_SIZE: usize = 1;
8-
pub const ACTIX_WEB_SERVER_PORT: usize = 3000;
8+
pub const HOME_ROUTE_REDIRECT_URL: &str = "https://opensauced.pizza";
99

1010
//OpenAI
1111
pub const CHAT_COMPLETION_TEMPERATURE: f64 = 0.7;

src/main.rs

+9-4
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@ mod routes;
88
mod utils;
99
use std::{path::Path, sync::Arc};
1010

11-
use actix_web::{web, App, HttpResponse, HttpServer};
12-
use constants::ACTIX_WEB_SERVER_PORT;
11+
use actix_cors::Cors;
12+
use actix_web::{web, App, HttpServer};
13+
use constants::HOME_ROUTE_REDIRECT_URL;
1314
use env_logger::Env;
1415
use tracing_actix_web::TracingLogger;
1516

@@ -21,18 +22,22 @@ async fn main() -> std::io::Result<()> {
2122

2223
let model: Arc<embeddings::Onnx> = Arc::new(embeddings::Onnx::new(Path::new("model")).unwrap());
2324
let db: Arc<db::QdrantDB> = Arc::new(db::QdrantDB::initialize().unwrap());
25+
let port = std::env::var("WEBSERVER_PORT").unwrap_or("3000".into());
26+
let port = port.parse::<u16>().expect("Invalid WEBSERVER_PORT");
2427

2528
HttpServer::new(move || {
29+
2630
App::new()
31+
.wrap(Cors::permissive())
2732
.wrap(TracingLogger::default())
28-
.route("/", web::get().to(HttpResponse::Ok))
33+
.service(web::redirect("/", HOME_ROUTE_REDIRECT_URL))
2934
.service(routes::embeddings)
3035
.service(routes::query)
3136
.service(routes::repo)
3237
.app_data(web::Data::new(model.clone()))
3338
.app_data(web::Data::new(db.clone()))
3439
})
35-
.bind(("0.0.0.0", ACTIX_WEB_SERVER_PORT as u16))?
40+
.bind(("0.0.0.0", port))?
3641
.run()
3742
.await
3843
}

0 commit comments

Comments
 (0)