feat: add self checking
This commit is contained in:
parent
3d08b14e0f
commit
abe9c6994d
52
src/actions/initialChecks.ts
Normal file
52
src/actions/initialChecks.ts
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
import fs from "fs";
|
||||||
|
|
||||||
|
const requiredEnvVars = ['MIGRATE_TXT', 'DB_FILE_NAME', 'MAILCONNECT_ROOT_DIR'];
|
||||||
|
|
||||||
|
function checkRatelimit() {
|
||||||
|
const ratelimitExists = fs.existsSync("ratelimit.json");
|
||||||
|
if (!ratelimitExists) {
|
||||||
|
console.log("[!] Ratelimit config not found");
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
console.log("[✓] Found ratelimit config");
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
function checkEnv() {
|
||||||
|
const envExists = fs.existsSync(".env");
|
||||||
|
if (!envExists) {
|
||||||
|
console.log("[!] .env file not found");
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
console.log("[✓] Found .env file");
|
||||||
|
let allVarsPresent = true;
|
||||||
|
|
||||||
|
for (const envVar of requiredEnvVars) {
|
||||||
|
if (!process.env[envVar]) {
|
||||||
|
console.log(` [!] ${envVar} not found`);
|
||||||
|
allVarsPresent = false;
|
||||||
|
} else {
|
||||||
|
console.log(` [✓] Found ${envVar}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!allVarsPresent) {
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
// the return value of this function determines if server should exit early
|
||||||
|
export default function initialChecks() {
|
||||||
|
const ratelimitCheck = checkRatelimit();
|
||||||
|
const envCheck = checkEnv();
|
||||||
|
|
||||||
|
if (!ratelimitCheck || !envCheck) {
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
};
|
@ -5,10 +5,20 @@ import { listAccounts } from "./actions/accounts/listAccounts";
|
|||||||
import { getUserAccount } from "./actions/accounts/getUserAccount";
|
import { getUserAccount } from "./actions/accounts/getUserAccount";
|
||||||
import { updatePassword } from "./actions/accounts/updatePassword";
|
import { updatePassword } from "./actions/accounts/updatePassword";
|
||||||
import { addAccount } from "./actions/accounts/addAccount";
|
import { addAccount } from "./actions/accounts/addAccount";
|
||||||
|
import initialChecks from "./actions/initialChecks";
|
||||||
|
|
||||||
const app = express();
|
const app = express();
|
||||||
app.use(express.json());
|
app.use(express.json());
|
||||||
|
|
||||||
|
console.log("==== SELF CHECK STARTING ====\n");
|
||||||
|
const rCResult = initialChecks();
|
||||||
|
if (!rCResult) {
|
||||||
|
console.log("\n==== SELF CHECK FAIL ====");
|
||||||
|
process.exit(1);
|
||||||
|
} else {
|
||||||
|
console.log("\n==== SELF CHECK PASS ====\n");
|
||||||
|
}
|
||||||
|
|
||||||
interface RateLimitOptions {
|
interface RateLimitOptions {
|
||||||
windowMs: number;
|
windowMs: number;
|
||||||
limit: number;
|
limit: number;
|
||||||
@ -35,7 +45,7 @@ app.listen(PORT, () => {
|
|||||||
console.log('mail-connect');
|
console.log('mail-connect');
|
||||||
console.log('Version: 0.1.1');
|
console.log('Version: 0.1.1');
|
||||||
console.log(`API listening on port ${PORT}\n`);
|
console.log(`API listening on port ${PORT}\n`);
|
||||||
console.dir("[!] " + err);
|
console.log("[!] " + err);
|
||||||
} else {
|
} else {
|
||||||
console.log(data);
|
console.log(data);
|
||||||
console.log('Version: 0.1.1');
|
console.log('Version: 0.1.1');
|
||||||
|
Loading…
x
Reference in New Issue
Block a user