'use strict'constconnect=require('gulp-connect')constos=require('os')constANY_HOST='0.0.0.0'constURL_RX=/(https?):\/\/(?:[^/: ]+)(:\d+)?/module.exports=(root,opts={},watch=undefined)=>(done)=>{connect.server({...opts,middleware:opts.host===ANY_HOST?decorateLog:undefined,root},function(){this.server.on('close',done)if(watch)watch()})}functiondecorateLog(_,app){const_log=app.logapp.log=(msg)=>{if(msg.startsWith('Server started ')){constlocalIp=getLocalIp()constreplacement='$1://localhost$2'+(localIp?` and $1://${localIp}$2`:'')msg=msg.replace(URL_RX,replacement)}_log(msg)}return[]}functiongetLocalIp(){for(constrecordsofObject.values(os.networkInterfaces())){for(constrecordofrecords){if(!record.internal&&record.family==='IPv4')returnrecord.address}}return'localhost'}