@stdlib/esm
Version:
ES module distribution for Stdlib, a standard library for JavaScript and Node.js.
3 lines • 2.37 kB
JavaScript
// This file is a part of stdlib. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0
import r from"./../vendor/http.js";import e from"./../vendor/debug.js";import t from"./../assert/is-function.js";import o from"./../assert/is-nonnegative-integer.js";import n from"./../assert/is-string.js";import i from"./../assert/is-plain-object.js";import s from"./../assert/has-own-property.js";var a=o.isPrimitive,p=n.isPrimitive,d=i,m=s;function v(r,e){return d(e)?m(e,"port")&&(r.port=e.port,!a(r.port))?new TypeError("invalid option. `port` must be a nonnegative integer. Option: `"+r.port+"`."):m(e,"maxport")&&(r.maxport=e.maxport,!a(r.maxport))?new TypeError("invalid option. `maxport` option must be a nonnegative integer. Option: `"+r.maxport+"`."):m(e,"hostname")&&(r.hostname=e.hostname,!p(r.hostname))?new TypeError("invalid option. `hostname` option must be a primitive string. Option: `"+r.hostname+"`."):m(e,"address")&&(r.address=e.address,!p(r.address))?new TypeError("invalid option. `address` option must be a primitive string. Option: `"+r.address+"`."):null:new TypeError("invalid argument. Options argument must be an object. Value: `"+e+"`.")}var u=0,l="127.0.0.1",f={port:u,address:l},g=r,h=e,c=t,b=v,w=f,x=h("@stdlib/net/http-server");function j(){var r,e,t,o,n,i,s,a;if(n={},1===(o=arguments.length))c(arguments[0])?r=arguments[0]:a=b(n,t=arguments[0]);else if(o>1){if(t=arguments[0],!c(r=arguments[1]))throw new TypeError("invalid argument. Request listener must be a function. Value: `"+r+"`.");a=b(n,t)}if(a)throw a;return i=void 0===n.port?w.port:n.port,x("Server port: %d",i),s=void 0===n.maxport?i:n.maxport,x("Max server port: %d",s),e=n.hostname?n.hostname:n.address?n.address:w.address,x("Server hostname: %s",e),p;function p(t){var o;if(!c(t))throw new TypeError("invalid argument. Callback must be a function. Value: `"+t+"`.");(o=r?g.createServer(r):g.createServer()).on("error",(function(r){if("EADDRINUSE"===r.code&&(x("Server address already in use: %s:%d.",e,i),(i+=1)<=s))return x("Attempting to listen on %s:%d.",e,i),void o.listen(i,e);throw r})),o.once("listening",(function(){var r=o.address();x("HTTP server initialized. Server is listening for requests on %s:%d.",r.address,r.port),t(null,o)})),x("Attempting to listen on %s:%d.",e,i),o.listen(i,e)}}var y=j;export default y;
//# sourceMappingURL=http-server.js.map