🔒 (security) security improvement

This commit is contained in:
2025-10-10 23:57:09 +07:00
parent 54f4e72b32
commit 15c9599ce7
54 changed files with 1603 additions and 1567 deletions

View File

@ -1,49 +1,49 @@
import fs from "fs";
import path from "path";
// These keys will not be cleared in the .env.example file
const PRESERVED_KEYS = ["APP_NAME", "APP_ENV", "APP_PORT"];
/**
* Script to create or update the .env.example file based on the .env file.
* It preserves certain keys and clears their values in the .env.example file.
*/
try {
const envPath = path.join(process.cwd(), ".env");
const envExamplePath = path.join(process.cwd(), ".env.example");
if (!fs.existsSync(envPath)) {
console.error(`.env file not found at ${envPath}`);
process.exit(1);
}
const envContent = fs.readFileSync(envPath, "utf-8");
const lines = envContent.split("\n");
const processedLines = lines.map((line) => {
const trimmedLine = line.trim();
if (trimmedLine.startsWith("#") || trimmedLine === "") {
return line;
}
const delimeterIndex = line.indexOf("=");
if (delimeterIndex === -1) {
return line;
}
const key = line.substring(0, delimeterIndex).trim();
const value = line.substring(delimeterIndex + 1).trim();
if (PRESERVED_KEYS.includes(key)) {
return `${key}=${value}`;
}
return `${key}=`;
});
fs.writeFileSync(envExamplePath, processedLines.join("\n"));
console.log("File .env.example berhasil diperbarui!");
} catch (error) {
console.error("Error while creating .env.example:", error);
process.exit(1);
}
import fs from "fs";
import path from "path";
// These keys will not be cleared in the .env.example file
const PRESERVED_KEYS = ["APP_NAME", "APP_ENV", "APP_PORT"];
/**
* Script to create or update the .env.example file based on the .env file.
* It preserves certain keys and clears their values in the .env.example file.
*/
try {
const envPath = path.join(process.cwd(), ".env");
const envExamplePath = path.join(process.cwd(), ".env.example");
if (!fs.existsSync(envPath)) {
console.error(`.env file not found at ${envPath}`);
process.exit(1);
}
const envContent = fs.readFileSync(envPath, "utf-8");
const lines = envContent.split("\n");
const processedLines = lines.map((line) => {
const trimmedLine = line.trim();
if (trimmedLine.startsWith("#") || trimmedLine === "") {
return line;
}
const delimeterIndex = line.indexOf("=");
if (delimeterIndex === -1) {
return line;
}
const key = line.substring(0, delimeterIndex).trim();
const value = line.substring(delimeterIndex + 1).trim();
if (PRESERVED_KEYS.includes(key)) {
return `${key}=${value}`;
}
return `${key}=`;
});
fs.writeFileSync(envExamplePath, processedLines.join("\n"));
console.log("File .env.example berhasil diperbarui!");
} catch (error) {
console.error("Error while creating .env.example:", error);
process.exit(1);
}

View File

@ -1,22 +1,22 @@
import { execSync } from "child_process";
/*
This script pushes the current branch to multiple remotes in a Git repository.
It is useful for deploying code to multiple servers or services at once.
Make sure you've set up your remotes correctly before running this script and do commit your changes first!
*/
const remotes = ["origin"]; // Add your remote names here, e.g., "origin", "vps", etc. if you have multiple remotes
// Start the push process
for (const remote of remotes) {
console.log(`Pushing to ${remote}...`);
try {
execSync(`git push ${remote} main`, { stdio: "inherit" });
} catch (err) {
console.error(`❌ Failed to push to ${remote}`);
}
}
// All remotes processed
console.log("✅ All remotes processed.");
import { execSync } from "child_process";
/*
This script pushes the current branch to multiple remotes in a Git repository.
It is useful for deploying code to multiple servers or services at once.
Make sure you've set up your remotes correctly before running this script and do commit your changes first!
*/
const remotes = ["origin"]; // Add your remote names here, e.g., "origin", "vps", etc. if you have multiple remotes
// Start the push process
for (const remote of remotes) {
console.log(`Pushing to ${remote}...`);
try {
execSync(`git push ${remote} main`, { stdio: "inherit" });
} catch (err) {
console.error(`❌ Failed to push to ${remote}`);
}
}
// All remotes processed
console.log("✅ All remotes processed.");