ollama-api-facade-js
Version:
OllamaApiFacadeJS is an open-source library for running an ExpressJS backend as an Ollama API using LangChainJS. It supports local language models services like LmStudio and allows seamless message conversion and streaming between LangChainJS and Ollama c
41 lines • 1.62 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.jsonRequestLogger = void 0;
/**
* Middleware for logging JSON requests and responses.
* This middleware logs the details of incoming requests and outgoing responses to the console.
* It helps in monitoring and debugging API interactions.
*/
const jsonRequestLogger = (request, response, next) => {
var _a;
const start = Date.now();
let requestBody = '';
console.log(`⬆️ [${request.method}] ${request.originalUrl}`);
console.log('🔍 Request Headers:', JSON.stringify(request.headers, null, 2));
if ((_a = request.headers.accept) === null || _a === void 0 ? void 0 : _a.includes('text/event-stream')) {
console.log('⚠️ Streaming-Request erkannt. Body wird nicht geloggt.');
return next();
}
request.on('data', (chunk) => {
requestBody += chunk;
});
request.on('end', () => {
if (requestBody) {
console.log('📥 Request Body:');
console.log(requestBody);
}
});
request.on('error', (err) => {
console.error('❌ Fehler beim Lesen des Request-Bodies:', err);
});
const originalSend = response.send;
response.send = function (body) {
console.log(`⬇️ [${request.method}] ${request.originalUrl} - ${response.statusCode} (${Date.now() - start}ms)`);
console.log('📤 Response Body:');
console.log(body);
return originalSend.call(this, body);
};
next();
};
exports.jsonRequestLogger = jsonRequestLogger;
//# sourceMappingURL=jsonRequestLogger.js.map