seperate all config files, move so i can just call @config
All checks were successful
Code quality checks / biome (push) Successful in 8s
All checks were successful
Code quality checks / biome (push) Successful in 8s
This commit is contained in:
parent
e98eebbb47
commit
9d8b3eb969
13 changed files with 77 additions and 76 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1,3 +1,4 @@
|
||||||
/node_modules
|
/node_modules
|
||||||
bun.lock
|
bun.lock
|
||||||
.env
|
.env
|
||||||
|
.vscode
|
||||||
|
|
12
config/cassandra.ts
Normal file
12
config/cassandra.ts
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
export const cassandra: CassandraConfig = {
|
||||||
|
host: process.env.CASSANDRA_HOST || "localhost",
|
||||||
|
port: Number.parseInt(process.env.CASSANDRA_PORT || "9042", 10),
|
||||||
|
keyspace: process.env.CASSANDRA_KEYSPACE || "void_db",
|
||||||
|
username: process.env.CASSANDRA_USERNAME || "",
|
||||||
|
password: process.env.CASSANDRA_PASSWORD || "",
|
||||||
|
datacenter: process.env.CASSANDRA_DATACENTER || "",
|
||||||
|
contactPoints: (process.env.CASSANDRA_CONTACT_POINTS || "localhost").split(
|
||||||
|
",",
|
||||||
|
),
|
||||||
|
authEnabled: process.env.CASSANDRA_AUTH_ENABLED !== "false",
|
||||||
|
};
|
|
@ -1,68 +0,0 @@
|
||||||
import { logger } from "@creations.works/logger";
|
|
||||||
|
|
||||||
const environment: Environment = {
|
|
||||||
port: Number.parseInt(process.env.PORT || "", 10),
|
|
||||||
host: process.env.HOST || "0.0.0.0",
|
|
||||||
development:
|
|
||||||
process.env.NODE_ENV === "development" || process.argv.includes("--dev"),
|
|
||||||
};
|
|
||||||
|
|
||||||
const redisTtl: number = process.env.REDIS_TTL
|
|
||||||
? Number.parseInt(process.env.REDIS_TTL, 10)
|
|
||||||
: 60 * 60 * 1; // 1 hour
|
|
||||||
|
|
||||||
const cassandra: CassandraConfig = {
|
|
||||||
host: process.env.CASSANDRA_HOST || "localhost",
|
|
||||||
port: Number.parseInt(process.env.CASSANDRA_PORT || "9042", 10),
|
|
||||||
keyspace: process.env.CASSANDRA_KEYSPACE || "void_db",
|
|
||||||
username: process.env.CASSANDRA_USERNAME || "",
|
|
||||||
password: process.env.CASSANDRA_PASSWORD || "",
|
|
||||||
datacenter: process.env.CASSANDRA_DATACENTER || "",
|
|
||||||
contactPoints: (process.env.CASSANDRA_CONTACT_POINTS || "localhost").split(
|
|
||||||
",",
|
|
||||||
),
|
|
||||||
authEnabled: process.env.CASSANDRA_AUTH_ENABLED === "false",
|
|
||||||
};
|
|
||||||
|
|
||||||
const jwt: JWTConfig = {
|
|
||||||
secret: process.env.JWT_SECRET || "",
|
|
||||||
expiration: process.env.JWT_EXPIRATION || "1h",
|
|
||||||
issuer: process.env.JWT_ISSUER || "",
|
|
||||||
algorithm: process.env.JWT_ALGORITHM || "HS256",
|
|
||||||
};
|
|
||||||
|
|
||||||
function verifyRequiredVariables(): void {
|
|
||||||
const requiredVariables = [
|
|
||||||
"HOST",
|
|
||||||
"PORT",
|
|
||||||
|
|
||||||
"REDIS_URL",
|
|
||||||
"REDIS_TTL",
|
|
||||||
|
|
||||||
"CASSANDRA_HOST",
|
|
||||||
"CASSANDRA_PORT",
|
|
||||||
"CASSANDRA_CONTACT_POINTS",
|
|
||||||
"CASSANDRA_AUTH_ENABLED",
|
|
||||||
"CASSANDRA_DATACENTER",
|
|
||||||
|
|
||||||
"JWT_SECRET",
|
|
||||||
"JWT_EXPIRATION",
|
|
||||||
"JWT_ISSUER",
|
|
||||||
];
|
|
||||||
|
|
||||||
let hasError = false;
|
|
||||||
|
|
||||||
for (const key of requiredVariables) {
|
|
||||||
const value = process.env[key];
|
|
||||||
if (value === undefined || value.trim() === "") {
|
|
||||||
logger.error(`Missing or empty environment variable: ${key}`);
|
|
||||||
hasError = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (hasError) {
|
|
||||||
process.exit(1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export { environment, cassandra, redisTtl, verifyRequiredVariables, jwt };
|
|
48
config/index.ts
Normal file
48
config/index.ts
Normal file
|
@ -0,0 +1,48 @@
|
||||||
|
import { logger } from "@creations.works/logger";
|
||||||
|
|
||||||
|
const environment: Environment = {
|
||||||
|
port: Number.parseInt(process.env.PORT || "", 10),
|
||||||
|
host: process.env.HOST || "0.0.0.0",
|
||||||
|
development:
|
||||||
|
process.env.NODE_ENV === "development" || process.argv.includes("--dev"),
|
||||||
|
};
|
||||||
|
|
||||||
|
function verifyRequiredVariables(): void {
|
||||||
|
const requiredVariables = [
|
||||||
|
"HOST",
|
||||||
|
"PORT",
|
||||||
|
|
||||||
|
"REDIS_URL",
|
||||||
|
"REDIS_TTL",
|
||||||
|
|
||||||
|
"CASSANDRA_HOST",
|
||||||
|
"CASSANDRA_PORT",
|
||||||
|
"CASSANDRA_CONTACT_POINTS",
|
||||||
|
"CASSANDRA_AUTH_ENABLED",
|
||||||
|
"CASSANDRA_DATACENTER",
|
||||||
|
|
||||||
|
"JWT_SECRET",
|
||||||
|
"JWT_EXPIRATION",
|
||||||
|
"JWT_ISSUER",
|
||||||
|
];
|
||||||
|
|
||||||
|
let hasError = false;
|
||||||
|
|
||||||
|
for (const key of requiredVariables) {
|
||||||
|
const value = process.env[key];
|
||||||
|
if (value === undefined || value.trim() === "") {
|
||||||
|
logger.error(`Missing or empty environment variable: ${key}`);
|
||||||
|
hasError = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hasError) {
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export * from "@config/cassandra";
|
||||||
|
export * from "@config/jwt";
|
||||||
|
export * from "@config/redis";
|
||||||
|
|
||||||
|
export { environment, verifyRequiredVariables };
|
6
config/jwt.ts
Normal file
6
config/jwt.ts
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
export const jwt: JWTConfig = {
|
||||||
|
secret: process.env.JWT_SECRET || "",
|
||||||
|
expiration: process.env.JWT_EXPIRATION || "1h",
|
||||||
|
issuer: process.env.JWT_ISSUER || "",
|
||||||
|
algorithm: process.env.JWT_ALGORITHM || "HS256",
|
||||||
|
};
|
3
config/redis.ts
Normal file
3
config/redis.ts
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
export const redisTtl: number = process.env.REDIS_TTL
|
||||||
|
? Number.parseInt(process.env.REDIS_TTL, 10)
|
||||||
|
: 60 * 60 * 1; // 1 hour
|
|
@ -1,10 +1,7 @@
|
||||||
import { readdir } from "node:fs/promises";
|
import { readdir } from "node:fs/promises";
|
||||||
import { extname, join, resolve } from "node:path";
|
import { extname, join, resolve } from "node:path";
|
||||||
import { pathToFileURL } from "node:url";
|
import { pathToFileURL } from "node:url";
|
||||||
import {
|
import { cassandra as cassandraConfig, verifyRequiredVariables } from "@config";
|
||||||
cassandra as cassandraConfig,
|
|
||||||
verifyRequiredVariables,
|
|
||||||
} from "@config/environment";
|
|
||||||
import { logger } from "@creations.works/logger";
|
import { logger } from "@creations.works/logger";
|
||||||
import { cassandra } from "@lib/cassandra";
|
import { cassandra } from "@lib/cassandra";
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import { serverHandler } from "@/server";
|
import { serverHandler } from "@/server";
|
||||||
import { verifyRequiredVariables } from "@config/environment";
|
import { verifyRequiredVariables } from "@config";
|
||||||
import { logger } from "@creations.works/logger";
|
import { logger } from "@creations.works/logger";
|
||||||
import { cassandra } from "@lib/cassandra";
|
import { cassandra } from "@lib/cassandra";
|
||||||
import { redis } from "bun";
|
import { redis } from "bun";
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { cassandra as config } from "@config/environment";
|
import { cassandra as config } from "@config";
|
||||||
import { logger } from "@creations.works/logger";
|
import { logger } from "@creations.works/logger";
|
||||||
import { Client, auth } from "cassandra-driver";
|
import { Client, auth } from "cassandra-driver";
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { environment, jwt } from "@config/environment";
|
import { environment, jwt } from "@config";
|
||||||
import { redis } from "bun";
|
import { redis } from "bun";
|
||||||
import { createDecoder, createSigner, createVerifier } from "fast-jwt";
|
import { createDecoder, createSigner, createVerifier } from "fast-jwt";
|
||||||
|
|
||||||
|
|
1
src/routes/user/delete.ts
Normal file
1
src/routes/user/delete.ts
Normal file
|
@ -0,0 +1 @@
|
||||||
|
// TODO: add after every other kinda of data related to the user
|
|
@ -1,5 +1,5 @@
|
||||||
import { resolve } from "node:path";
|
import { resolve } from "node:path";
|
||||||
import { environment } from "@config/environment";
|
import { environment } from "@config";
|
||||||
import { logger } from "@creations.works/logger";
|
import { logger } from "@creations.works/logger";
|
||||||
import { jsonResponse } from "@lib/http";
|
import { jsonResponse } from "@lib/http";
|
||||||
import {
|
import {
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
"baseUrl": "./",
|
"baseUrl": "./",
|
||||||
"paths": {
|
"paths": {
|
||||||
"@/*": ["src/*"],
|
"@/*": ["src/*"],
|
||||||
|
"@config": ["config/index.ts"],
|
||||||
"@config/*": ["config/*"],
|
"@config/*": ["config/*"],
|
||||||
"@types/*": ["types/*"],
|
"@types/*": ["types/*"],
|
||||||
"@lib/*": ["src/lib/*"]
|
"@lib/*": ["src/lib/*"]
|
||||||
|
|
Loading…
Add table
Reference in a new issue