|
4 | 4 |
|
5 | 5 | NOTE: The following implementation steps have been developed and tested using this [Docker image](https://github.com/fabiocicerchia/nginx-lua). |
6 | 6 |
|
7 | | -Copy [KnownUserNginxHandler.lua](https://github.com/queueit/KnownUser.V3.Lua/blob/master/Handlers/KnownUserNginxHandler.lua) and folders ([SDK](https://github.com/queueit/KnownUser.V3.Lua/tree/master/SDK) and [Helpers](https://github.com/queueit/KnownUser.V3.Lua/tree/master/Helpers)) incl. their content to your NGINX filesystem (in the following example we have added it to `usr/queueit`). |
| 7 | +1) Copy the handler file and the following two folders from this repository to your NGINX filesystem. In the following example we will use `./usr/queueit` as the base path. |
| 8 | + * [KnownUserNginxHandler.lua](https://github.com/queueit/KnownUser.V3.Lua/blob/master/Handlers/KnownUserNginxHandler.lua) -> `./usr/queueit/KnownUserNginxHandler.lua` |
| 9 | + * [SDK](https://github.com/queueit/KnownUser.V3.Lua/tree/master/SDK) -> `./usr/queueit/SDK` |
| 10 | + * [Helpers](https://github.com/queueit/KnownUser.V3.Lua/tree/master/Helpers) -> `./usr/queueit/Helpers` |
| 11 | + |
8 | 12 |
|
9 | | -Then update/add `lua_package_path` in your `nginx.conf` to include the new path (keep `;;` in the end which means default path): |
| 13 | +2) Update or add the `lua_package_path` configuration option in your `nginx.conf` to include the new paths. Make sure to keep `;;` in the end which means default path: |
10 | 14 |
|
11 | | -``` |
12 | | -http { |
13 | | - lua_package_path "./usr/queueit/?.lua;./usr/queueit/SDK/?.lua;./usr/queueit/Helpers/?/?.lua;;"; |
14 | | -} |
15 | | -``` |
16 | | - |
17 | | -Then update `conf.d/default.conf`: |
18 | | -``` |
19 | | -server { |
20 | | - location / { |
21 | | - rewrite_by_lua_block { |
22 | | - local customerId = "{CUSTOMER_ID}" |
23 | | - local secretKey = "{SECRET_KEY}" |
24 | | -
|
25 | | - -- Basic example where integration configuration file is loaded from disk. |
26 | | - -- You will need to decide where to store and load this file (caching layer, database ect.). |
27 | | - -- Remember this will be done on all requests, so the selected option must be fast (not causing bottlenecks). |
28 | | - local integrationConfigFilePath = "./usr/queueit/integrationconfig.json" |
29 | | - local integrationConfigFile = io.open(integrationConfigFilePath, "rb") |
30 | | - local integrationConfigJson = integrationConfigFile:read("*all") |
31 | | - integrationConfigFile:close() |
| 15 | + ``` |
| 16 | + http { |
| 17 | + lua_package_path "./usr/queueit/?.lua;./usr/queueit/SDK/?.lua;./usr/queueit/Helpers/?/?.lua;;"; |
| 18 | + } |
| 19 | + ``` |
32 | 20 |
|
33 | | - local qit = require("KnownUserNginxHandler") |
| 21 | +3) Then update the configuration file relative to the location you want to be protected by Queue-it (`conf.d/default.conf` or similar): |
| 22 | + |
| 23 | + ``` |
| 24 | + server { |
| 25 | + location / { |
| 26 | + rewrite_by_lua_block { |
| 27 | + local customerId = "{CUSTOMER_ID}" |
| 28 | + local secretKey = "{SECRET_KEY}" |
| 29 | + |
| 30 | + -- Basic example where integration configuration file is loaded from disk. |
| 31 | + -- You will need to decide where to store and load this file (caching layer, database ect.). |
| 32 | + -- Remember this will be done on all requests, so the selected option must be fast (not causing bottlenecks). |
| 33 | + local integrationConfigFilePath = "./usr/queueit/integrationconfig.json" |
| 34 | + local integrationConfigFile = io.open(integrationConfigFilePath, "r") |
| 35 | + local integrationConfigJson = integrationConfigFile:read("*a") |
| 36 | + integrationConfigFile:close() |
| 37 | + |
| 38 | + local qit = require("KnownUserNginxHandler") |
| 39 | + |
| 40 | + -- If you want to enable secure or http only cookie settings then change options below. |
| 41 | + -- httpOnly: Only enable if you use pure server-side integration e.g. not JS Hybrid. |
| 42 | + -- secure: Only enable if your website runs purely on https. |
| 43 | + qit.setOptions({ httpOnly = false, secure = false }) |
| 44 | + |
| 45 | + qit.handleByIntegrationConfig(customerId, secretKey, integrationConfigJson) |
| 46 | + } |
| 47 | + } |
| 48 | + ``` |
| 49 | + |
| 50 | + * Replace the following two placeholders in the above code `{CUSTOMER_ID}` and `{SECRET_KEY}` with respective values located in GO Queue-it platform. |
| 51 | + * NOTE: In this example `rewrite_by_lua_block` directive was added to default location `/` but you must decide what makes sense in your case. |
| 52 | + |
34 | 53 |
|
35 | | - -- If you want to enable secure or http only cookie settings then change options below. |
36 | | - -- httpOnly: Only enable if you use pure server-side integration e.g. not JS Hybrid. |
37 | | - -- secure: Only enable if your website runs purely on https. |
38 | | - qit.setOptions({ httpOnly = false, secure = false }) |
| 54 | +4) Provide the `integrationconfig.json`... |
39 | 55 |
|
40 | | - qit.handleByIntegrationConfig(customerId, secretKey, integrationConfigJson) |
41 | | - } |
42 | | -} |
43 | | -``` |
44 | | -In this example `rewrite_by_lua_block` have been added to default location `/` but you must decide what makes sense in your case. |
45 | 56 |
|
46 | | -Please note the comments in the code about providing `integrationconfig.json` and replacing `CUSTOMER_ID` and `SECRET_KEY` with correct credentials located in GO Queue-it platform. |
47 | 57 |
|
48 | 58 | ### Request body trigger (advanced) |
49 | 59 | Nginx handler (incl. Lua SDK) supports triggering on request body content. Example could be a POST call with specific item ID where you want end-users to queue up for. |
|
0 commit comments