var http = require('http'),
    ,spawn = require('child_process').spawn


function onRequest(req, res) {
    var reqUrl = req.url    
    if ('/' == reqUrl || 'favicon.ico' == reqUrl) {
        return res.end('Im debugger')
        }

    res.writeHead(200 ,{'Content-Type': 'text/plain','Cache-Control': 'no-cache,no-store'})
        }
    var logFile = 'xxxxx'
    tailLog(logFile)
    req.on('close' ,function(){
        console.log('aborted')
        req.tail.kill('SIGHUP')
        })

    function tailLog(logFile) {
        //console.log(logFile)    
        logFile = logFile.trim()
        if (!logFile) return res.end('Log File lost')
        var tail  = req.tail = spawn('tail' , ['-f' , logFile])
        tail.stdout.on('data' , function(data){
            var line = data.toString('utf-8')
            console.log(line)    
            res.write(line)
            })
        }
}


var arguments = process.argv.splice(2)
http.createServer(onRequest).listen(arguments[0] || 2014)

 

服务通过 nginx 反向代理后 要注意 conf 里需要配置 proxy_buffering off;  不然 nginx 要一直等 node,没有任何响应

相关文章:

  • 2022-12-23
  • 2021-06-16
  • 2021-05-17
  • 2021-06-18
  • 2021-05-18
  • 2021-12-15
  • 2021-05-24
猜你喜欢
  • 2022-03-04
  • 2022-01-22
  • 2022-12-23
  • 2022-12-23
  • 2021-08-25
  • 2021-09-07
  • 2022-01-20
相关资源
相似解决方案