Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
13fdb40
feat: add health check server with configuration and scripts
jzunigax2 Nov 3, 2025
c2fd0a8
feat: add error handling and logging plugins for Fastify
jzunigax2 Nov 3, 2025
778ec53
feat: implement health check server with main routes and configuration
jzunigax2 Nov 5, 2025
ddad320
feat: extend configuration and add health check error handling utility
jzunigax2 Nov 7, 2025
b2026fc
feat: implement cryptographic utilities for password hashing and text…
jzunigax2 Nov 7, 2025
5030236
feat: add drive login route for health check and authentication utili…
jzunigax2 Nov 7, 2025
15be4b3
feat: add acess check route
jzunigax2 Nov 7, 2025
ed664c7
feat: implement key generation and encryption utilities for user regi…
jzunigax2 Nov 10, 2025
d63baa8
feat: enhance configuration and implement user signup route with encr…
jzunigax2 Nov 10, 2025
cbd8bef
feat: update environment configuration with additional variables
jzunigax2 Nov 11, 2025
0fd34ef
feat: implement file upload route for health check with network and s…
jzunigax2 Nov 11, 2025
d841757
feat: add drive files retrieval route
jzunigax2 Nov 12, 2025
b14d41c
fix: fix file upload encryption
jzunigax2 Nov 12, 2025
d4f7b10
feat: add drive download route for health check with file decryption …
jzunigax2 Nov 12, 2025
a250600
fix: change drive download route from POST to GET for improved access
jzunigax2 Nov 12, 2025
cbb1ef7
fix: rename file upload route to /drive/files
jzunigax2 Nov 12, 2025
20a86a4
Merge branch 'feat/file-upload-health-check' of https://github.com/in…
jzunigax2 Nov 12, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions health-check-server/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
PORT=3000
NODE_ENV=development
API_URL=https://api.internxt.com
AUTH_TOKEN=your-jwt-token-here
CLIENT_NAME=health-check-server
CLIENT_VERSION=1.0.0
CRYPTO_SECRET=your-crypto-secret-here
LOGIN_EMAIL=
LOGIN_PASSWORD=
MAGIC_IV=
MAGIC_SALT=
NETWORK_URL=
6 changes: 6 additions & 0 deletions health-check-server/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
node_modules/
dist/
.env
*.log
.DS_Store

29 changes: 29 additions & 0 deletions health-check-server/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"name": "@internxt/health-check-server",
"version": "1.0.0",
"description": "Health check server for monitoring Internxt API endpoints",
"private": true,
"main": "dist/index.js",
"scripts": {
"dev": "tsx watch src/index.ts",
"build": "tsc",
"start": "node dist/index.js",
"typecheck": "tsc --noEmit"
},
"dependencies": {
"@dashlane/pqc-kem-kyber512-node": "^1.0.0",
"@fastify/env": "^4.4.0",
"bip39": "^3.1.0",
"crypto-js": "^4.2.0",
"dotenv": "^16.4.5",
"fastify": "^4.28.1",
"openpgp": "^5.11.3"
},
"devDependencies": {
"@types/crypto-js": "^4.2.2",
"@types/node": "^20.14.10",
"pino-pretty": "^11.2.1",
"tsx": "^4.16.2",
"typescript": "^5.9.3"
}
}
45 changes: 45 additions & 0 deletions health-check-server/src/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { config as loadEnv } from 'dotenv';
import { Config } from './types';

loadEnv();

function loadConfig(): Config {
const requiredVars = [
'API_URL',
'AUTH_TOKEN',
'CLIENT_NAME',
'CLIENT_VERSION',
'LOGIN_EMAIL',
'LOGIN_PASSWORD',
'CRYPTO_SECRET',
'MAGIC_IV',
'MAGIC_SALT',
'NETWORK_URL',
];

const missing = requiredVars.filter((varName) => !process.env[varName]);

if (missing.length > 0) {
throw new Error(
`Missing required environment variables: ${missing.join(', ')}\n` +
'Please ensure all required variables are set in your .env file',
);
}

return {
port: Number.parseInt(process.env.PORT ?? '7001'),
apiUrl: process.env.API_URL!,
authToken: process.env.AUTH_TOKEN!,
clientName: process.env.CLIENT_NAME!,
clientVersion: process.env.CLIENT_VERSION!,
nodeEnv: process.env.NODE_ENV || 'development',
loginEmail: process.env.LOGIN_EMAIL!,
loginPassword: process.env.LOGIN_PASSWORD!,
cryptoSecret: process.env.CRYPTO_SECRET!,
magicIv: process.env.MAGIC_IV!,
magicSalt: process.env.MAGIC_SALT!,
networkUrl: process.env.NETWORK_URL!,
};
}

export const config = loadConfig();
64 changes: 64 additions & 0 deletions health-check-server/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import Fastify from 'fastify';
import { config } from './config';
import { loggingPlugin } from './plugins/logging';
import { errorHandlerPlugin } from './plugins/errorHandler';
import { driveRoutes } from './routes/drive';

async function start() {
const fastify = Fastify({
logger: {
level: config.nodeEnv === 'development' ? 'info' : 'warn',
transport:
config.nodeEnv === 'development'
? {
target: 'pino-pretty',
options: {
translateTime: 'HH:MM:ss Z',
ignore: 'pid,hostname',
},
}
: undefined,
},
});

try {
await fastify.register(loggingPlugin);
await fastify.register(errorHandlerPlugin);

await fastify.register(driveRoutes);

fastify.get('/health', async () => {
return {
status: 'healthy',
service: 'health-check-server',
timestamp: new Date().toISOString(),
uptime: process.uptime(),
};
});

await fastify.listen({
port: config.port,
host: '0.0.0.0',
});

fastify.log.info('Health check server started successfully');
fastify.log.info(`Listening on port ${config.port}`);
fastify.log.info(`API URL: ${config.apiUrl}`);
fastify.log.info(`Environment: ${config.nodeEnv}`);
} catch (error) {
fastify.log.error(error);
process.exit(1);
}
}

process.on('SIGINT', () => {
process.stdout.write('\nShutting down gracefully...\n');
process.exit(0);
});

process.on('SIGTERM', () => {
process.stdout.write('\nShutting down gracefully...\n');
process.exit(0);
});

start();
30 changes: 30 additions & 0 deletions health-check-server/src/plugins/errorHandler.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { FastifyInstance, FastifyError, FastifyRequest, FastifyReply } from 'fastify';

/**
* Error handler plugin for Fastify
* Transforms errors into standardized health check responses
*/
export async function errorHandlerPlugin(fastify: FastifyInstance) {
fastify.setErrorHandler(async (error: FastifyError, request: FastifyRequest, reply: FastifyReply) => {
request.log.error(
{
error: error.message,
stack: error.stack,
url: request.url,
method: request.method,
},
'Error occurred during request',
);

const statusCode = error.statusCode ?? 503;

return reply.status(statusCode).send({
status: 'unhealthy',
endpoint: request.url,
timestamp: new Date().toISOString(),
error: error.message,
});
});

fastify.log.info('Error handler plugin registered');
}
32 changes: 32 additions & 0 deletions health-check-server/src/plugins/logging.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { FastifyInstance, FastifyRequest, FastifyReply } from 'fastify';

/**
* Logging plugin for Fastify
* Logs all incoming requests and their responses
*/
export async function loggingPlugin(fastify: FastifyInstance) {
fastify.addHook('onRequest', async (request: FastifyRequest) => {
request.log.info(
{
method: request.method,
url: request.url,
userAgent: request.headers['user-agent'],
},
'Incoming request',
);
});

fastify.addHook('onResponse', async (request: FastifyRequest, reply: FastifyReply) => {
request.log.info(
{
method: request.method,
url: request.url,
statusCode: reply.statusCode,
responseTime: reply.elapsedTime,
},
'Request completed',
);
});

fastify.log.info('Logging plugin registered');
}
Loading
Loading