Skip to content

Tutorial 4

knightliao edited this page Mar 4, 2016 · 1 revision

Tutorial 4 统一的pfrock服务

正常的项目中, 我们肯定是让项目统一接入 pfrock, 由 pfrock 作为统一代理为项目的所有请求进行服务.

  • 我们可以随心所欲的对任何URL, 任何method进行mock.
  • 并且可以对不想mock的URL, 还是让他请求原来要请求的服务.

通过此种方式, 我们可以以最低的侵入性, 实现为系统的部分接口进行mock.

这里以 https://github.com/knightliao/pfrock/tree/master/demo 为demo

配置文件

{
    "servers": [
        {
            "port": 8888,
            "routes": [
                {
                    "path": "/api1/(.*)",
                    "handler": "pfrock_static_plugin",
                    "options": {
                        "routes": [
                            {
                                "path": "json",
                                "file": "mocks/static/a.json"
                            },
                            {
                                "dir": "mocks/static"
                            }
                        ]
                    }
                },
                {
                    "path": "/api",
                    "methods": [
                        "GET"
                    ],
                    "handler": "pfrock_http_plugin",
                    "options": {
                        "handler": "mocks.handler.hello_world.HelloWorldHandler",
                        "query": "1!",
                        "pageno": 1
                    }
                },
                {
                    "path": ".*",
                    "methods": "any",
                    "handler": "pfrock_proxy_plugin",
                    "options": {
                        "url": "http://www.sov5.com"
                    }
                }
            ]
        }
    ]
}
Clone this wiki locally