Hi, community,

@liuxiran previously submitted a nice PR that implements route publish and
offline feature [1].

We hope that instead of releasing a route immediately, we can test it
first, and release it after the test result is OK.

So we think it is more suitable to implement this feature directly in
`Apache APISIX` instead of dashboard.

Here is the implementation steps in my mind:

1. Add an `enable` field, or another more suitable field to the route
configuration, and the default value of the field is false when adding a
route. Which means the route is not released.

2. Add a matching item `enable` similar to `host` or `method` in the
`lua-resty-radixtree` library.
When matching a route for client request, If the value of `enable` is
false, skip the route directly.
But when there is `X-APISIX-ROUTE-DEBUG` in the http header and the value
is true, routes which `enable` are false can be matched according to other
conditions.

3. Now, normal client requests will skip routes not released, and requests
for testing by specifying the http header `X-APISIX-ROUTE-DEBUG` can match
routes not released, thus realizing our needs.

Example:

1. Create a route (it's not released by default)

```shell
$ curl http://127.0.0.1:9080/apisix/admin/routes/1 -H'X-API-KEY:
edd1c9f034335f136f87ad84b625c8f1'-X PUT -i -d'
{
    "Uri": "/route-debug-test",
    "Upstream": {
        "Type": "roundrobin",
        "node":{
            "127.0.0.1:80": 1
        }
    }
}'
```
2. Normal request (404 not found)
```
curl 127.0.0.1:9080/route-debug-test
```

3. Debugging (200)
```
curl 127.0.0.1:9080/route-debug-test -H "X-APISIX-ROUTE-DEBUG: true"
```

4. Release the route
```
$ curl http://127.0.0.1:9080/apisix/admin/routes/1 -H'X-API-KEY:
edd1c9f034335f136f87ad84b625c8f1'-X PATCH -i -d'
{
    "Status": 0
}'
```

5. Normal access (200)
```
curl 127.0.0.1:9080/route-debug-test
```


[1] https://github.com/apache/apisix-dashboard/pull/451

Reply via email to