Skip to content

Commit

Permalink
[doc] grammar nazi readme fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
mayorova committed May 10, 2017
1 parent f0f7b13 commit c2ee8b5
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions examples/custom-module/README.md
Original file line number Diff line number Diff line change
@@ -1,35 +1,35 @@
# Custom Module

Module is something, that is executed in each nginx phase: init, init_worker, rewrite, access, content, log, post_action, balancer, header_filter, body_filter, ...
Module is something, that is executed in each nginx phase: init, init_worker, rewrite, access, content, log, post_action, balancer, header_filter, body_filter etc.
It handles processing of each request. There can be only ONE module that is being executed.

The name of the module that is executed is defined by environment variable `APICAST_MODULE` and defaults to `apicast`.
The name of the module that is executed is defined by the environment variable `APICAST_MODULE` and defaults to `apicast`.

This example implements a module that extends apicast default one and adds more logging.
The example described in this README implements a module that extends the default `apicast` module and adds more logging.

There is another example of custom module implementation for IP blacklisting in [`blacklist.lua`](blacklist.lua).

## Starting the gateway

```sh
APICAST_MODULE=$(pwd)/verbose.lua ../../bin/apicast -c $(pwd)/../configuration/local.json
```

This starts apicast with module `verbose.lua` instead of the default [`apicast.lua`](https://github.com/3scale/apicast/blob/master/apicast/src/apicast.lua). Using local configuration so no 3scale account is needed.
This starts APIcast with module `verbose.lua` instead of the default [`apicast.lua`](https://github.com/3scale/apicast/blob/master/apicast/src/apicast.lua). Local configuration file is used, so no 3scale account is needed.

## Testing

```sh
curl 'localhost:8080?user_key=foo'
```

And see in the apicast output:
And see in the APIcast output:

```
2016/11/16 16:52:00 [warn] 98009#0: *5 [lua] verbose.lua:7: call(): upstream response time: 0.001 upstream connect time: 0.000 while logging request, client: 127.0.0.1, server: _, request: "GET /?user_key=foo HTTP/1.1", upstream: "http://127.0.0.1:8081/?user_key=foo", host: "echo"
```

## Writing own module

There is example module of IP blacklist in [`blacklist.lua`](blacklist.lua).
## Writing a custom module

To honour the module inheritance, but still be able to override some methods from the `apicast` module, you'll
need some clever use of metatables. Here is a recommended skeleton of the module inheritance:
Expand All @@ -48,11 +48,11 @@ local mt = { __index = setmetatable(_M, { __index = apicast }) }

function _M.new()
-- this method is going to get called after this file is required
-- so create new table for internal state (global) and set the metatable for inheritance
-- so create a new table for the internal state (global) and set the metatable for inheritance
return setmetatable({}, mt)
end

-- to run some custom code in log phase lets override the method
-- to run some custom code in the log phase let's override the method
function _M.log()
ngx.log(ngx.WARN,
'upstream response time: ', ngx.var.upstream_response_time, ' ',
Expand Down

1 comment on commit c2ee8b5

@mikz
Copy link
Contributor

@mikz mikz commented on c2ee8b5 May 10, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! Very much appreciated 🥇

Please sign in to comment.