added proplt for key stored in memory, also improved vite script

This commit is contained in:
subnub
2024-12-30 02:55:29 -05:00
parent 6856eaea1e
commit e65ac93edb
4 changed files with 53 additions and 21 deletions
+20 -12
View File
@@ -1,24 +1,32 @@
import env from "../enviroment/env";
import crypto from "crypto";
import getWebUIKey from "./get-web-UI-key";
import getKeyFromTerminal from "../utils/getKeyFromTerminal";
const getKey = async () => {
if (process.env.KEY) {
// For Docker
if (process.env.KEY || process.env.NODE_ENV === "development") {
const password = process.env.KEY;
if (!password) {
console.log("Key is required for development server");
throw new Error("Key is required for development server");
}
env.key = crypto.createHash("md5").update(password).digest("hex");
} else if (process.env.NODE_ENV === "production") {
let password = await getWebUIKey();
} else if (process.env.NODE_ENV === "production" && !process.env.KEY) {
const terminalPassword = await getKeyFromTerminal();
password = crypto.createHash("md5").update(password).digest("hex");
if (!terminalPassword || !terminalPassword.length) {
console.log(
"Terminal key is required for production server, or create a .env file with KEY"
);
throw new Error(
"Terminal key is required for production server, or create a .env file with KEY"
);
}
env.key = password;
} else {
let password = "1234";
password = crypto.createHash("md5").update(password).digest("hex");
const password = crypto
.createHash("md5")
.update(terminalPassword)
.digest("hex");
env.key = password;
}
+17
View File
@@ -0,0 +1,17 @@
import prompts from "prompts";
const getKeyFromTerminal = async () => {
return new Promise<string>((resolve, _) => {
setTimeout(async () => {
const response = await prompts({
type: "password",
name: "key",
message: "Enter Server Encryption Key",
});
resolve(response.key);
}, 1500);
});
};
export default getKeyFromTerminal;
+2 -1
View File
@@ -82,7 +82,7 @@
"password-prompt": "^1.1.2",
"postcss": "^8.4.38",
"progress-stream": "^2.0.0",
"prompts": "^2.3.1",
"prompts": "^2.4.2",
"raf": "^3.4.1",
"react": "^18.3.1",
"react-circular-progressbar": "^2.1.0",
@@ -111,6 +111,7 @@
"@types/fluent-ffmpeg": "^2.1.24",
"@types/lodash": "^4.17.5",
"@types/nodemailer": "^6.4.15",
"@types/prompts": "^2.4.9",
"concurrently": "^8.2.2",
"cross-env": "^6.0.3",
"dart-sass": "^1.25.0",
+14 -8
View File
@@ -1,6 +1,10 @@
import { defineConfig } from "vite";
import react from "@vitejs/plugin-react";
// Here you can set the proxy URL if you are using a proxy server
// This is only used for development
const proxyURL = "http://localhost:3000";
export default defineConfig({
plugins: [react()],
build: {
@@ -11,13 +15,15 @@ export default defineConfig({
},
envDir: "./src/config/",
server: {
proxy: {
"/api": {
target: "htto://localhost:3000", // The port where your backend is running
changeOrigin: true,
rewrite: (path) => path.replace(/^\/api/, ""),
},
},
host: true,
proxy: proxyURL
? {
"/api": {
target: proxyURL, // The port where your backend is running
changeOrigin: true,
rewrite: (path) => path.replace(/^\/api/, ""),
},
}
: undefined,
host: proxyURL ? true : undefined,
},
});