Download api/server/middleware/validateEndpoint.js from Zhitomir/chat: direct link, hf CLI and curl.
- Browser
- Download file 538 Bytes
-
https://huggingface.co/spaces/Zhitomir/chat/resolve/main/api/server/middleware/validateEndpoint.js
- Command line
-
hf download hf://spaces/Zhitomir/chat/api/server/middleware/validateEndpoint.js
-
curl -L -o validateEndpoint.js https://huggingface.co/spaces/Zhitomir/chat/resolve/main/api/server/middleware/validateEndpoint.js
538 Bytes
| const { handleError } = require('../utils'); | |
| 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; | |