servers.ts 785 B

1234567891011121314151617181920212223242526272829
  1. import express from 'express'
  2. import { HttpStatusCode } from '@peertube/peertube-models'
  3. import { getHostWithPort } from '../helpers/express-utils.js'
  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.fail({
  11. status: HttpStatusCode.INTERNAL_SERVER_ERROR_500,
  12. message: 'Could not parse hosts'
  13. })
  14. }
  15. req.body.hosts[i] = hostWithPort
  16. }
  17. return next()
  18. }
  19. // ---------------------------------------------------------------------------
  20. export {
  21. setBodyHostsPort
  22. }