mirror of
https://github.com/ninenines/cowboy.git
synced 2025-07-16 05:00:24 +00:00
Add middleware support
Middlewares allow customizing the request processing. All existing Cowboy project are incompatible with this commit. You need to change `{dispatch, Dispatch}` in the protocol options to `{env, [{dispatch, Dispatch}]}` to fix your code.
This commit is contained in:
parent
73d86057f2
commit
1b3f510b7e
12 changed files with 529 additions and 251 deletions
|
@ -135,18 +135,15 @@ handler to run instead of having to parse the routes repeatedly.
|
|||
|
||||
This can be done with a simple call to `cowboy_routing:compile/1`.
|
||||
|
||||
@todo Note that the `routes` option will be specified slightly differently
|
||||
when middleware support gets in.
|
||||
|
||||
``` erlang
|
||||
{ok, Routes} = cowboy_routing:compile([
|
||||
%% {URIHost, list({URIPath, Handler, Opts})}
|
||||
%% {HostMatch, list({PathMatch, Handler, Opts})}
|
||||
{'_', [{'_', my_handler, []}]}
|
||||
]),
|
||||
%% Name, NbAcceptors, TransOpts, ProtoOpts
|
||||
cowboy:start_http(my_http_listener, 100,
|
||||
[{port, 8080}],
|
||||
[{routes, Routes}]
|
||||
[{env, [{routes, Routes}]}]
|
||||
).
|
||||
```
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue