servers.ts 656 B

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