فهرست منبع

Change port back to 8000.
Add production db connection.
Change isProduction to be changed on database.

Lee Morgan 10 ماه پیش
والد
کامیت
dca3adee78
2فایلهای تغییر یافته به همراه10 افزوده شده و 4 حذف شده
  1. 9 3
      src/main.rs
  2. 1 1
      src/views/createHtml.js

+ 9 - 3
src/main.rs

@@ -1,5 +1,5 @@
 use actix_web::{App, HttpServer, web};
-use std::sync::OnceLock;
+use std::{sync::OnceLock, env};
 use mongodb::{Client, Database};
 
 mod routes;
@@ -13,7 +13,13 @@ pub static HTML: OnceLock<String> = OnceLock::new();
 
 #[actix_web::main]
 async fn main() -> std::io::Result<()> {
-    let db = connect_db("mongodb://localhost:27017", "suma").await;
+    let node_env = env::var("NODE_ENV").unwrap_or_else(|_| "development".to_string());
+    let uri = if node_env == "production" {
+        env::var("MONGO_URI").expect("MONGO_URI must be set in production")
+    } else {
+        "mongodb://127.0.0.1:27017".to_string()
+    };
+    let db = connect_db(&uri, "suma").await;
 
     let html = std::fs::read_to_string("src/views/build.html")
         .expect("Failed to read HTML");
@@ -27,7 +33,7 @@ async fn main() -> std::io::Result<()> {
             .configure(routes::account::config)
             .configure(routes::transaction::config)
     })
-        .bind(("0.0.0.0", 5001))?
+        .bind(("0.0.0.0", 8000))?
         .run()
         .await
 }

+ 1 - 1
src/views/createHtml.js

@@ -4,7 +4,7 @@ import htmlMinifier from "html-minifier-terser";
 import fsSync from "fs";
 
 const fs = fsSync.promises;
-const isProduction = process.env.NODE_ENV === "production";
+const isProduction = false;
 
 const esbuildProm = esbuild.build({
     entryPoints: [`${import.meta.dirname}/js/index.js`, `${import.meta.dirname}/css/index.css`],