LibreChat/api/server/middleware/validateEndpoint.js
Danny Avila 2e1874e596
🔧 fix: handleError import path to use '@librechat/api' (#8415)
* 🔧 fix: Update handleError import path to use '@librechat/api' in middleware files

* chore: import order

* chore: import order

---------

Co-authored-by: Atef Bellaaj <slalom.bellaaj@external.daimlertruck.com>
2025-07-11 13:29:51 -04:00

20 lines
544 B
JavaScript

const { handleError } = require('@librechat/api');
function validateEndpoint(req, res, next) {
const { endpoint: _endpoint, endpointType } = req.body;
const endpoint = endpointType ?? _endpoint;
if (!req.body.text || req.body.text.length === 0) {
return handleError(res, { text: 'Prompt empty or too short' });
}
const pathEndpoint = req.baseUrl.split('/')[3];
if (endpoint !== pathEndpoint) {
return handleError(res, { text: 'Illegal request: Endpoint mismatch' });
}
next();
}
module.exports = validateEndpoint;