Refactor code structure for improved readability and maintainability
This commit is contained in:
@@ -10,7 +10,7 @@
|
|||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"cors": "^2.8.5",
|
"cors": "^2.8.5",
|
||||||
"dotenv": "^16.4.5",
|
"dotenv": "^16.6.1",
|
||||||
"express": "^4.19.2",
|
"express": "^4.19.2",
|
||||||
"helmet": "^7.1.0",
|
"helmet": "^7.1.0",
|
||||||
"jsonwebtoken": "^9.0.2",
|
"jsonwebtoken": "^9.0.2",
|
||||||
|
|||||||
1096
pnpm-lock.yaml
generated
Normal file
1096
pnpm-lock.yaml
generated
Normal file
File diff suppressed because it is too large
Load Diff
32
src/index.js
32
src/index.js
@@ -1,7 +1,4 @@
|
|||||||
import dotenv from 'dotenv';
|
import dotenv from 'dotenv';
|
||||||
import fs from 'fs';
|
|
||||||
import path from 'path';
|
|
||||||
import { fileURLToPath } from 'url';
|
|
||||||
import express from 'express';
|
import express from 'express';
|
||||||
import http from 'http';
|
import http from 'http';
|
||||||
import cors from 'cors';
|
import cors from 'cors';
|
||||||
@@ -13,33 +10,8 @@ import lobbyRoutes from './routes/lobby.js';
|
|||||||
import walletRoutes from './routes/wallet.js';
|
import walletRoutes from './routes/wallet.js';
|
||||||
import pool from './db.js';
|
import pool from './db.js';
|
||||||
import { setupWebSocket } from './ws.js';
|
import { setupWebSocket } from './ws.js';
|
||||||
|
import dotenv from 'dotenv';
|
||||||
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
dotenv.config();
|
||||||
const envCandidates = [
|
|
||||||
path.join(process.cwd(), '.env'),
|
|
||||||
path.join(__dirname, '..', '.env'),
|
|
||||||
path.join(__dirname, '..', '..', '.env')
|
|
||||||
];
|
|
||||||
|
|
||||||
let envLoaded = false;
|
|
||||||
for (const candidate of envCandidates) {
|
|
||||||
if (fs.existsSync(candidate)) {
|
|
||||||
dotenv.config({ path: candidate });
|
|
||||||
envLoaded = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!envLoaded) {
|
|
||||||
// eslint-disable-next-line no-console
|
|
||||||
console.warn('Figyelem: .env fajl nem talalhato, ENV valtozok nelkul indul.');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!process.env.DB_HOST) {
|
|
||||||
// eslint-disable-next-line no-console
|
|
||||||
console.error('Hiba: DB_HOST nincs beallitva. Ellenorizd az .env fajlt vagy az ENV valtozokat.');
|
|
||||||
process.exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
const app = express();
|
const app = express();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user