text: const Koa = require('koa');
  let app = new Koa();
  
  const middleware = function(app) {
    // 中间件在初始化实例 把getServerInfo方法 挂载代理到上下文
    app.context.getServerInfo = function() {
      function parseMem( mem = 0 ) {
        let memVal = mem / 1024 / 1024;
        memVal = memVal.toFixed(2) + 'MB';
        return memVal;
      }
      
      function getMemInfo() {
        let memUsage = process.memoryUsage();
        let rss = parseMem(memUsage.rss);
        let heapTotal = parseMem(memUsage.heapTotal);
        let heapUsed =  parseMem(memUsage.heapUsed);
        return {
          pid: process.pid,
          rss,
          heapTotal,
          heapUsed
        }
      }
      return getMemInfo()
    };
  }
  
  middleware(app);
  
  const page = async function(ctx, next) {
    const serverInfo = ctx.getServerInfo();
    ctx.body = `
        <html>
          <head></head>
          <body>
            <p>${JSON.stringify(serverInfo)}</p>
          </body>
        </html>
      `; 
  }
  
  app.use(page);
  
  app.listen(3001, function(){
    console.log('the demo is start at port 3001');
  })