npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

koa2-record

v1.0.5

Published

记录koa的请求和响应

Downloads

17

Readme

record request and response

记录请求和响应数据

install

npm install koa2-record

usage

var koa = require('koa');
var app = new koa();
var record = require('koa2-record');
var remote = require('koa2-remote');

app.use(record.callback());

app.use(function (ctx, next) {
  // 修改header的host,后面将从该host处加载数据
  ctx.request.header.host = 'laomu1988.github.io';
  return next();
});


app.use(remote());  // 从远程加载数据

app.listen(3000, function (err) {
  err && console.log(err) || console.log('start server at http://localhost:3000/');
});

api

  • config(dir) 配置记录存放目录
  • config({dir, callback}) 配置存放目录和有记录时的回调地址
  • clean() 清空记录数据
  • callback(onRecord) 生成koa@next的中间件,当有新的请求或者响应返回时调用onRecord
  • getInfo(id,[callback]) 获取记录的详细情况,返回promise
  • getBody(id,[encode],[callback]) 获取记录的返回数据,返回promise
  • getPath(id) 获取记录信息位置和body存放路径,返回{info:'info_path',body: 'body_path'}
  • getList() 文件夹内获取所有的记录id

info介绍

onRecord和config配置中的callback触发时将有两个参数,ctx和info,其中ctx为koa@next中的ctx对象,info部分数据和ctx保持一致,info对象有如下属性
  • id: 记录id
  • startTime: 请求开始时间
  • endTime: 请求结束时间
  • request: 请求内容
    • url
    • host
    • protocol
    • method
    • header
    • body
  • response 响应内容(请求阶段时未定义)
    • status
    • statusString
    • header

todo

  • [x] 清理数据
  • [x] 请求内容是否被修改过
  • [x] 响应的body类型
  • [x] 获取列表

history

  • v1.0.4
    • 删除changed.host,增加changed.remote
  • v1.0.3
    • 增加method,record_id修改为id
  • v1.0.2
    • 增加getPath,获取存放info和response body的路径
  • v1.0.1
    • 清理文件clean
    • getBody增加参数编码getBody(record_id,[encode],[callback])
  • v1.0.0
    • 记录请求