src/admin/md/configuration-file.md
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
## Configuration File As of version 1.8.0, you can specify a configuration file containing settings, middleware and authorization configuration using the **--config** or **-c** command line option: [litestore -c:config.json](class:cmd) A typical configuration file looks like this: ``` { "settings": { "log": "debug", "port": 9200 }, "resources": { "/docs/vehicles/*": { "GET": { "middleware": ["validate", "log"] }, "HEAD": { "middleware": ["validate", "log"] }, "POST": { "allowed": false }, "PATCH": { "auth": ["admin:vehicles"], "middleware": ["validate", "log"] }, "PUT": { "auth": ["admin:vehicles"], "middleware": ["validate", "log"] }, "DELETE": { "auth": ["admin:vehicles"], "middleware": ["validate", "log"] } }, "/docs/logs/*": { "GET": { "auth": ["admin:server"] }, "POST": { "allowed": false }, "PUT": { "allowed": false }, "PATCH": { "allowed": false }, "DELETE": { "allowed": false } } }, "signature": "\n-----BEGIN CERTIFICATE-----\n<certificate text goes here>\n-----END CERTIFICATE-----\n" } ``` At present, it contains a [settings](class:kwd), a [resources](class:kwd), and a [signature](class:kwd) section. ### settings This section contains some of the most common command-line options, i.e.: * address * port * store * directory * mount * readonly * middleware * log If a configuration file is specified and some of these settings are configured, they will be recognized as if they were specified via command line. However, if you also specify the same settings via command line, the command line settings will take precedence over the settings defined in the configuration file. ### resources This section can contain any number of resource paths, like [/docs/](class:kwd), [/info/](class:kwd), [/docs/vehicles/AA456CC](class:kwd) or [/docs/logs/*](class:kwd). If a wildcard is specified after a resource or folder path, the rules defined within that section will match any document within the specified path. So for examople [/docs/vehicles/*](class:kwd) will match both [/docs/vehicles/AB547QV](class:kwd) and [/docs/vehicles/BB326CZ](class:kwd), but *not* [/docs/vehicles/](class:kwd). Within each resource path, you can specify different HTTP methods (all uppercase) and within each method any of the following properties: * **auth** — A list of JWT scopes necessary to access the specified resource with the specified method. * **middleware** — A list of middleware function definitions that will be executed in sequence when the resource is accessed with the specified method. * **allowed** — If set to **false**, LiteStore will return a [405 - Method not allowed](class:kwd) error code when accessing the resource with the specified method. ### signature This section must be set to a valid certificate used validate JWT tokens. Note that the certificate must follow a specific format and start with the appropriate begin/end blocks. |