all repos — litestore @ b2e879b5c0dd44183091612cdd954a274120f655

A minimalist nosql document store.

Updated documentation.
h3rald h3rald@h3rald.com
Sun, 29 Nov 2015 16:00:05 +0100
commit

b2e879b5c0dd44183091612cdd954a274120f655

parent

c8eb2c121c366045a17bda258b3e14bc8ace8b62

M admin/js/components/navbar.jsadmin/js/components/navbar.js

@@ -20,6 +20,7 @@ {path: "/guide/usage", title: "Usage"},

{path: "/guide/admin_app", title: "Administration App"}, {path: "/guide/api", title: "HTTP API Reference"}, {path: "/guide/api_info", title: caret+"info (LiteStore Information)"}, + {path: "/guide/api_dir", title: caret+"dir (LiteStore Directory)"}, {path: "/guide/api_docs", title: caret+"docs (LiteStore Documents)"}, {path: "/guide/credits", title: "Credits"} ];

@@ -116,4 +117,4 @@ ])

]); } }; -}());+}());
A admin/md/api_dir.md

@@ -0,0 +1,38 @@

+### info (LiteStore Information) + +This resource can be queried to retrieve files within the served directory (specied via **-d**). + +#### OPTIONS info + +Returns the allowed HTTP verbs for this resource. + +##### Example + +``` +$ curl -i -X OPTIONS http://127.0.0.1:9500/v1/dir +HTTP/1.1 200 OK +Content-Length: 0 +Access-Control-Allow-Methods: GET,OPTIONS +Allow: GET,OPTIONS +Access-Control-Allow-Headers: Content-Type +Access-Control-Allow-Origin: * +Server: LiteStore/1.0.0 +``` + +#### GET dir/:id + +Returns the content of a file within the served directory (if it exists). + +##### Example + +``` +$ curl -i http://127.0.0.1:9500/v1/dir/test.txt +HTTP/1.1 200 OK +Content-Length: 25 +Content-Type: text/plain +Access-Control-Allow-Headers: Content-Type +Access-Control-Allow-Origin: * +Server: LiteStore/1.0.3 + +This is a test text file. +```
M admin/md/api_docs.mdadmin/md/api_docs.md

@@ -39,7 +39,7 @@ Access-Control-Allow-Methods: HEAD,GET,OPTIONS,POST

Allow: HEAD,GET,OPTIONS,POST Access-Control-Allow-Headers: Content-Type Access-Control-Allow-Origin: * -Server: LiteStore/1.0.0 +Server: LiteStore/1.0.3 ``` #### OPTIONS docs/:id

@@ -68,7 +68,7 @@ Content-Length: 197

Content-Type: application/json Access-Control-Allow-Headers: Content-Type Access-Control-Allow-Origin: * -Server: LiteStore/1.0.0 +Server: LiteStore/1.0.3 {"id": "555f93e82190e77500000000", "data": "A document with a randomly-generated ID.", "created": "2015-05-22T08:39:04Z", "modified": null, "tags": ["$type:text", "$subtype:plain", "$format:text"]} ```

@@ -84,7 +84,7 @@ Content-Length: 0

Content-Type: application/json Access-Control-Allow-Headers: Content-Type Access-Control-Allow-Origin: * -Server: LiteStore/1.0.0 +Server: LiteStore/1.0.3 ``` #### HEAD docs/:id

@@ -98,7 +98,7 @@ Content-Length: 0

Content-Type: application/json Access-Control-Allow-Headers: Content-Type Access-Control-Allow-Origin: * -Server: LiteStore/1.0.0 +Server: LiteStore/1.0.3 ``` #### GET docs

@@ -130,7 +130,7 @@ Content-Length: 1960

Content-Type: application/json Access-Control-Allow-Headers: Content-Type Access-Control-Allow-Origin: * -Server: LiteStore/1.0.0 +Server: LiteStore/1.0.3 { "search": "Use Cases",

@@ -197,7 +197,7 @@ Content-Length: 24

Content-Type: text/plain Access-Control-Allow-Headers: Content-Type Access-Control-Allow-Origin: * -Server: LiteStore/1.0.0 +Server: LiteStore/1.0.3 This is a test document. ```

@@ -211,7 +211,7 @@ Content-Length: 191

Content-Type: application/json Access-Control-Allow-Headers: Content-Type Access-Control-Allow-Origin: * -Server: LiteStore/1.0.0 +Server: LiteStore/1.0.3 {"id": "test", "data": "This is a test document.", "created": "2015-09-19T08:07:43Z", "modified": null, "tags": ["$type:text", "$subtype:plain", "$format:text"]} ```

@@ -227,7 +227,7 @@ Content-Length: 161

Content-Type: application/json Access-Control-Allow-Headers: Content-Type Access-Control-Allow-Origin: * -Server: LiteStore/1.0.0 +Server: LiteStore/1.0.3 {"id": "test", "data": "This is a test document.", "created": "2015-05-22T08:40:00Z", "modified": null, "tags": ["$type:text", "$subtype:plain", "$format:text"]} ```

@@ -251,7 +251,7 @@ Content-Length: 187

Content-Type: application/json Access-Control-Allow-Headers: Content-Type Access-Control-Allow-Origin: * -Server: LiteStore/1.0.0 +Server: LiteStore/1.0.3 {"id": "test.json", "data": {"test": true}, "created": "2015-09-20T09:06:25Z", "modified": null, "tags": ["$type:application", "$subtype:json", "$format:text", "test1", "test2", "test3"]} ```

@@ -268,5 +268,5 @@ HTTP/1.1 204 No Content

Content-Length: 0 Access-Control-Allow-Headers: Content-Type Access-Control-Allow-Origin: * -Server: LiteStore/1.0.0 -```+Server: LiteStore/1.0.3 +```
M admin/md/api_info.mdadmin/md/api_info.md

@@ -16,7 +16,7 @@ Access-Control-Allow-Methods: GET,OPTIONS

Allow: GET,OPTIONS Access-Control-Allow-Headers: Content-Type Access-Control-Allow-Origin: * -Server: LiteStore/1.0.0 +Server: LiteStore/1.0.3 ``` #### GET info

@@ -41,7 +41,7 @@ Content-Length: 965

Content-Type: application/json Access-Control-Allow-Headers: Content-Type Access-Control-Allow-Origin: * -Server: LiteStore/1.0.0 +Server: LiteStore/1.0.3 { "version": "LiteStore v1.0.0",

@@ -71,4 +71,4 @@ "$subtype:html": 2

} ] } -```+```
M admin/md/getting-started.mdadmin/md/getting-started.md

@@ -5,12 +5,12 @@ ### Downloading Pre-built Binaries

The easiest way to get LiteStore is by downloading one of the prebuilt binaries from the [Github Release Page][release]: - * [LiteStore for Mac OS X (x64)](https://github.com/h3rald/litestore/releases/download/v1.0.2litestore_v1.0.2_macosx_x64.zip) -- Compiled on OS X Yosemite (LLVM CLANG 6.0) - * [LiteStore for Windows (x64)](https://github.com/h3rald/litestore/releases/download/v1.0.2/litestore_v1.0.2_windows_x64.zip) -- Cross-compiled on OS X Yosemite (MinGW-w64 GCC 4.8.2) - * [LiteStore for Windows (x86)](https://github.com/h3rald/litestore/releases/download/v1.0.2/litestore_v1.0.2_windows_x86.zip) -- Cross-compiled on OS X Yosemite (MinGW-w64 GCC 4.8.2) - * [LiteStore for Linux (x64)](https://github.com/h3rald/litestore/releases/download/v1.0.2/litestore_v1.0.2_linux_x64.zip) -- Cross-compiled on OS X Yosemite (GNU GCC 4.8.1) - * [LiteStore for Linux (x86)](https://github.com/h3rald/litestore/releases/download/v1.0.2/litestore_v1.0.2_linux_x86.zip) -- Cross-compiled on OS X Yosemite (GNU GCC 4.8.1) - * [LiteStore for Linux (ARM)](https://github.com/h3rald/litestore/releases/download/v1.0.2/litestore_v1.0.2_linux_arm.zip) -- Cross-compiled on OS X Yosemite (GNU GCC 4.8.2) + * [LiteStore for Mac OS X (x64)](https://github.com/h3rald/litestore/releases/download/v1.0.3litestore_v1.0.3_macosx_x64.zip) -- Compiled on OS X El Capitan (LLVM CLANG 7.0.0) + * [LiteStore for Windows (x64)](https://github.com/h3rald/litestore/releases/download/v1.0.3/litestore_v1.0.3_windows_x64.zip) -- Cross-compiled on OS X El Capitan (MinGW-w64 GCC 4.8.2) + * [LiteStore for Windows (x86)](https://github.com/h3rald/litestore/releases/download/v1.0.3/litestore_v1.0.3_windows_x86.zip) -- Cross-compiled on OS X El Capitan (MinGW-w64 GCC 4.8.2) + * [LiteStore for Linux (x64)](https://github.com/h3rald/litestore/releases/download/v1.0.3/litestore_v1.0.3_linux_x64.zip) -- Cross-compiled on OS X El Capitan (GNU GCC 4.8.1) + * [LiteStore for Linux (x86)](https://github.com/h3rald/litestore/releases/download/v1.0.3/litestore_v1.0.3_linux_x86.zip) -- Cross-compiled on OS X El Capitan (GNU GCC 4.8.1) + * [LiteStore for Linux (ARM)](https://github.com/h3rald/litestore/releases/download/v1.0.3/litestore_v1.0.3_linux_arm.zip) -- Cross-compiled on OS X El Capitan (GNU GCC 4.8.2) ### Installing using Nimble

@@ -32,7 +32,7 @@ A simple but functional Administration App is available to manage LiteStore, create documents interactively, view and search content, etc.

To get the app up and running (assuming that you have the [litestore](class:cmd) executable in your path): -1. Download the default [data.db](https://github.com/h3rald/litestore/releases/download/v1.0.2/data.db) file. This file is a LiteStore data store file containing the sample app. +1. Download the default [data.db](https://github.com/h3rald/litestore/releases/download/v1.0.3/data.db) file. This file is a LiteStore data store file containing the sample app. 2. Go to the local directory in which you downloaded the [data.db](class:cmd) file. 3. Run [litestore -s:data.db](class:cmd) 4. Go to <http://localhost:9500/docs/admin/index.html>.
M admin/md/usage.mdadmin/md/usage.md

@@ -16,7 +16,7 @@

#### Options * **-a**, **-\-address** &mdash; Specify server address (default: 127.0.0.1). -* **-d**, **-\-directory** &mdash; Specify a directory to import, export, delete, or mount. +* **-d**, **-\-directory** &mdash; Specify a directory to serve, import, export, delete, or mount. * **-h**, **-\-help** &mdash; Display program usage. * **-l**, **-\-log** &mdash; Specify the log level: debug, info, warn, error, none (default: info) * **-m**, **-\-mount** &mdash; Mirror database changes to the specified directory on the filesystem.

@@ -40,7 +40,11 @@ * in read-only mode with logging level set to **debug**:

[litestore -r -l:debug](class:cmd) -* mouting a directory called **admin** (changes will be mirrored to filesystem): +* serving the contents of a directory called **admin**: + + [litestore -d:admin](class:cmd) + +* mouting a directory called **admin** (changes will be mirrored to filesystem, directory contents will be served): [litestore -d:admin -m](class:cmd)

@@ -70,4 +74,4 @@ [litestore vacuum](class:cmd)

* optimize search index: - [litestore optimize](class:cmd)+ [litestore optimize](class:cmd)
M build_guidebuild_guide

@@ -9,6 +9,7 @@ md/usage.md

md/admin_app.md md/api.md md/api_info.md + md/api_dir.md md/api_docs.md md/credits.md )
M lib/api_v1.nimlib/api_v1.nim

@@ -10,6 +10,7 @@ os,

times import types, + contenttypes, core, utils, logger

@@ -63,7 +64,6 @@ proc parseQueryOptions(querystring: string, options: var QueryOptions) =

var fragments = querystring.split('&') for f in fragments: f.parseQueryOption(options) - proc validate(req: Request, LS: LiteStore, resource: string, id: string, cb: proc(req: Request, LS: LiteStore, resource: string, id: string):Response): Response = if req.reqMethod == "POST" or req.reqMethod == "PUT" or req.reqMethod == "PATCH":

@@ -304,6 +304,12 @@ result.content = ""

result.headers = TAB_HEADERS.newStringTable result.headers["Allow"] = "GET,OPTIONS" result.headers["Access-Control-Allow-Methods"] = "GET,OPTIONS" + of "dir": + result.code = Http200 + result.content = "" + result.headers = TAB_HEADERS.newStringTable + result.headers["Allow"] = "GET,OPTIONS" + result.headers["Access-Control-Allow-Methods"] = "GET,OPTIONS" of "docs": if id != "": result.code = Http200

@@ -400,6 +406,32 @@ if id != "":

return LS.patchDocument(id, req.body) else: return resError(Http400, "Bad request: document ID must be specified in PATCH requests.") + +proc serveFile*(req: Request, LS: LiteStore, id: string): Response = + let path = LS.directory / id + var reqMethod = req.reqMethod + if req.headers.hasKey("X-HTTP-Method-Override"): + reqMethod = req.headers["X-HTTP-Method-Override"] + case reqMethod.toUpper: + of "OPTIONS": + return validate(req, LS, "dir", id, options) + of "GET": + if path.fileExists: + try: + let contents = path.readFile + let parts = path.splitFile + if CONTENT_TYPES.hasKey(parts.ext): + result.headers = CONTENT_TYPES[parts.ext].ctHeader + else: + result.headers = ctHeader("text/plain") + result.content = contents + result.code = Http200 + except: + return resError(Http500, "Unable to read file '$1'." % path) + else: + return resError(Http404, "File '$1' not found." % path) + else: + return resError(Http405, "Method not allowed: $1" % req.reqMethod) proc route*(req: Request, LS: LiteStore, resource = "docs", id = ""): Response = var reqMethod = req.reqMethod
M lib/core.nimlib/core.nim

@@ -294,7 +294,7 @@ var d_id = f.replace("\\", "/")

var d_contents = f.readFile var d_ct = "application/octet-stream" if CONTENT_TYPES.hasKey(ext): - d_ct = CONTENT_TYPES[ext].getStr + d_ct = CONTENT_TYPES[ext].replace("\"", "") var d_binary = 0 var d_searchable = 1 if d_ct.isBinary:
M lib/server.nimlib/server.nim

@@ -10,7 +10,6 @@ cgi,

os import types, - contenttypes, utils, api_v1

@@ -26,23 +25,6 @@ proc handleCtrlC() {.noconv.} =

echo "" LOG.info("Exiting...") quit() - -proc serveFile(req: Request, LS: LiteStore, id: string): Response = - let path = LS.directory / id - if path.fileExists: - try: - let contents = path.readFile - let parts = path.splitFile - if CONTENT_TYPES.hasKey(parts.ext): - result.headers = CONTENT_TYPES[parts.ext].ctHeader - else: - result.headers = ctHeader("text/plain") - result.content = contents - result.code = Http200 - except: - return resError(Http500, "Unable to read file '$1'." % path) - else: - return resError(Http404, "File '$1' not found." % path) proc processApiUrl(req: Request, LS: LiteStore, info: ResourceInfo): Response = if info.version == "v1" and info.resource.match(peg"^docs / info$"):