mirror of
https://dev.azure.com/tstanciu94/PhantomMind/_git/Bitip
synced 2025-10-13 01:52:19 +03:00
Compare commits
No commits in common. "bb19edd7e31b22776858eca2a09d7d1e1f3db599" and "fe91e1461297373c6e63f2955b8c6f4da489f492" have entirely different histories.
bb19edd7e3
...
fe91e14612
@ -109,7 +109,6 @@ ENABLE_HTTPS_SECURITY=false
|
|||||||
- Useful for reverse proxy scenarios or hosting multiple apps on same domain
|
- Useful for reverse proxy scenarios or hosting multiple apps on same domain
|
||||||
- **Example**: `/geoip-ui`
|
- **Example**: `/geoip-ui`
|
||||||
- **Note**: All API routes are prefixed with this path automatically
|
- **Note**: All API routes are prefixed with this path automatically
|
||||||
- **Health Check**: The `/api/health` endpoint is ALWAYS available at root (`/api/health`) for Docker HEALTHCHECK compatibility, AND also at `{BASE_PATH}/api/health` for consistency
|
|
||||||
|
|
||||||
**`NODE_ENV`**
|
**`NODE_ENV`**
|
||||||
|
|
||||||
|
@ -1,35 +0,0 @@
|
|||||||
import { Request, Response } from 'express';
|
|
||||||
import geoIPService from '../services/geoip.js';
|
|
||||||
import logger from '../services/logger.js';
|
|
||||||
|
|
||||||
export const healthCheckHandler = async (
|
|
||||||
_req: Request,
|
|
||||||
res: Response
|
|
||||||
): Promise<void> => {
|
|
||||||
try {
|
|
||||||
const isHealthy = await geoIPService.healthCheck();
|
|
||||||
|
|
||||||
if (isHealthy) {
|
|
||||||
res.json({
|
|
||||||
status: 'healthy',
|
|
||||||
timestamp: new Date().toISOString(),
|
|
||||||
service: 'Bitip GeoIP Service',
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
res.status(503).json({
|
|
||||||
status: 'unhealthy',
|
|
||||||
timestamp: new Date().toISOString(),
|
|
||||||
service: 'Bitip GeoIP Service',
|
|
||||||
error: 'GeoIP service health check failed',
|
|
||||||
});
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
logger.error('Health check failed', error as Error);
|
|
||||||
res.status(503).json({
|
|
||||||
status: 'unhealthy',
|
|
||||||
timestamp: new Date().toISOString(),
|
|
||||||
service: 'Bitip GeoIP Service',
|
|
||||||
error: 'Health check endpoint failed',
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
|
@ -1 +0,0 @@
|
|||||||
export * from './healthHandler.js';
|
|
@ -12,7 +12,6 @@ import dynamicRateLimit from './middleware/rateLimit.js';
|
|||||||
import config from './services/config.js';
|
import config from './services/config.js';
|
||||||
import logger from './services/logger.js';
|
import logger from './services/logger.js';
|
||||||
import { generateRuntimeConfig } from './services/runtimeConfig.js';
|
import { generateRuntimeConfig } from './services/runtimeConfig.js';
|
||||||
import { healthCheckHandler } from './handlers';
|
|
||||||
|
|
||||||
const __filename = fileURLToPath(import.meta.url);
|
const __filename = fileURLToPath(import.meta.url);
|
||||||
const __dirname = dirname(__filename);
|
const __dirname = dirname(__filename);
|
||||||
@ -77,9 +76,6 @@ const frontendPath = path.join(__dirname, '../frontend');
|
|||||||
// Generate runtime configuration (env.js) at startup
|
// Generate runtime configuration (env.js) at startup
|
||||||
generateRuntimeConfig(frontendPath, basePath);
|
generateRuntimeConfig(frontendPath, basePath);
|
||||||
|
|
||||||
// Health check endpoint at root (always accessible for Docker HEALTHCHECK)
|
|
||||||
app.get('/api/health', healthCheckHandler);
|
|
||||||
|
|
||||||
// API routes with authentication and rate limiting
|
// API routes with authentication and rate limiting
|
||||||
app.use(`${basePath}/api`, apiKeyAuth, dynamicRateLimit, apiRoutes);
|
app.use(`${basePath}/api`, apiKeyAuth, dynamicRateLimit, apiRoutes);
|
||||||
|
|
||||||
|
@ -6,7 +6,6 @@ import { dirname, join } from 'path';
|
|||||||
import geoIPService from '../services/geoip.js';
|
import geoIPService from '../services/geoip.js';
|
||||||
import logger from '../services/logger.js';
|
import logger from '../services/logger.js';
|
||||||
import config from '../services/config.js';
|
import config from '../services/config.js';
|
||||||
import { healthCheckHandler } from '../handlers';
|
|
||||||
import {
|
import {
|
||||||
BatchGeoIPRequest,
|
BatchGeoIPRequest,
|
||||||
BatchGeoIPResponse,
|
BatchGeoIPResponse,
|
||||||
@ -253,7 +252,34 @@ router.post('/lookup/batch', async (req: Request, res: Response) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Health check
|
// Health check
|
||||||
router.get('/health', healthCheckHandler);
|
router.get('/health', async (req: Request, res: Response) => {
|
||||||
|
try {
|
||||||
|
const isHealthy = await geoIPService.healthCheck();
|
||||||
|
|
||||||
|
if (isHealthy) {
|
||||||
|
res.json({
|
||||||
|
status: 'healthy',
|
||||||
|
timestamp: new Date().toISOString(),
|
||||||
|
service: 'Bitip GeoIP Service',
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
res.status(503).json({
|
||||||
|
status: 'unhealthy',
|
||||||
|
timestamp: new Date().toISOString(),
|
||||||
|
service: 'Bitip GeoIP Service',
|
||||||
|
error: 'GeoIP service health check failed',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
logger.error('Health check failed', error as Error);
|
||||||
|
res.status(503).json({
|
||||||
|
status: 'unhealthy',
|
||||||
|
timestamp: new Date().toISOString(),
|
||||||
|
service: 'Bitip GeoIP Service',
|
||||||
|
error: 'Health check endpoint failed',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// Get app version
|
// Get app version
|
||||||
router.get('/version', (_req: Request, res: Response): void => {
|
router.get('/version', (_req: Request, res: Response): void => {
|
||||||
|
@ -15,10 +15,10 @@
|
|||||||
integrity="sha256-p4NxAoJBhIIN+hmNHrzRCf9tD/miZyoHS5obTRR9BMY="
|
integrity="sha256-p4NxAoJBhIIN+hmNHrzRCf9tD/miZyoHS5obTRR9BMY="
|
||||||
crossorigin=""
|
crossorigin=""
|
||||||
/>
|
/>
|
||||||
<script src="/env.js"></script>
|
|
||||||
<script type="module" src="/src/main.tsx"></script>
|
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div id="root"></div>
|
<div id="root"></div>
|
||||||
|
<script src="/env.js"></script>
|
||||||
|
<script type="module" src="/src/main.tsx"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user