servers.ts 629 B

12345678910111213141516171819202122232425
  1. import * as express from 'express'
  2. import { getHostWithPort } from '../helpers/express-utils'
  3. function setBodyHostsPort (req: express.Request, res: express.Response, next: express.NextFunction) {
  4. if (!req.body.hosts) return next()
  5. for (let i = 0; i < req.body.hosts.length; i++) {
  6. const hostWithPort = getHostWithPort(req.body.hosts[i])
  7. // Problem with the url parsing?
  8. if (hostWithPort === null) {
  9. return res.sendStatus(500)
  10. }
  11. req.body.hosts[i] = hostWithPort
  12. }
  13. return next()
  14. }
  15. // ---------------------------------------------------------------------------
  16. export {
  17. setBodyHostsPort
  18. }