diff --git a/README.md b/README.md index 859d0f86..52598413 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,3 @@ # Alwatr Storage -An extremely fast and compact json-based database with memory cache. +This is an extremely fast and compact JSON-based database that operates in memory, includes a JSON file backup, and serve over the highly accelerated Nginx. diff --git a/packages/nginx/data/error.json b/packages/nginx/data/error.json deleted file mode 100644 index f4591ba9..00000000 --- a/packages/nginx/data/error.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "ok": false, - "statusCode": , - "errorCode": "serve_storage_error", - "meta": { - "server": "alwatr/storage", - "status": "" - } -} diff --git a/packages/nginx/etc/nginx/templates/http.d/49-map-bearer-token.conf.template b/packages/nginx/etc/nginx/templates/http.d/49-map-bearer-token.conf.template new file mode 100644 index 00000000..e6b73f94 --- /dev/null +++ b/packages/nginx/etc/nginx/templates/http.d/49-map-bearer-token.conf.template @@ -0,0 +1,4 @@ +map $http_authorization $bearer_token { + ~*^Bearer\s+(?\S+)$ $token; + default ''; +} diff --git a/packages/nginx/etc/nginx/templates/location.d/10-error-page.conf.template b/packages/nginx/etc/nginx/templates/location.d/10-error-page.conf.template deleted file mode 100644 index c6385f77..00000000 --- a/packages/nginx/etc/nginx/templates/location.d/10-error-page.conf.template +++ /dev/null @@ -1,8 +0,0 @@ -error_page 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 421 422 423 424 425 426 428 429 431 451 500 501 502 503 504 505 506 507 508 510 511 /_error.json; - -location = /_error.json { - internal; - ssi on; - ssi_types *; - auth_basic off; -} diff --git a/packages/nginx/etc/nginx/templates/location.d/90-home-json.conf.template b/packages/nginx/etc/nginx/templates/location.d/90-home-json.conf.template index 87aab1f8..be0cd619 100644 --- a/packages/nginx/etc/nginx/templates/location.d/90-home-json.conf.template +++ b/packages/nginx/etc/nginx/templates/location.d/90-home-json.conf.template @@ -1,5 +1,5 @@ location = / { # return static json for home page default_type application/json; - return 200 '{"ok": true, "data": "..:: Alwatr Accelerated Storage Server ::.."}'; + return 200 '{"ok": true, "data": "..:: Alwatr Storage Server ::.."}'; } diff --git a/packages/nginx/etc/nginx/templates/location.d/91-json.conf.template b/packages/nginx/etc/nginx/templates/location.d/91-json.conf.template new file mode 100644 index 00000000..483f0fa8 --- /dev/null +++ b/packages/nginx/etc/nginx/templates/location.d/91-json.conf.template @@ -0,0 +1,47 @@ +# Serves all data for public users without requiring any token. +# If data is not found, it returns a 200 status code with `data: null`. +location ~ ^(/api)?/v\d+/publistore/hub/(?.*)$ { + try_files /publistore/hub/$doc_path.json @null_data; +} + +# If data is not found, it returns a 200 status code with `data: null`. +location ~ ^(/api)?/v\d+/publistore/vault/(?.*)$ { + if ($bearer_token = "") { + return 401; + } + if (!-d $document_root/publistore/auth/$bearer_token) { + return 403; + } + + try_files /publistore/vault/$doc_path.json @null_data; +} + +# Serves private data that varies for each authenticated user who provides a valid bearer token. +# If data is not found, it returns a 200 status code with `data: null`. +location ~ ^(/api)?/v\d+/publistore/auth/(?.*)$ { + location ~ ^/auth/(?.*)$ { + if ($bearer_token = "") { + return 401; + } + if (!-d $document_root/publistore/auth/$bearer_token) { + return 403; + } + + try_files /publistore/auth/$bearer_token/$doc_path.json @null_data; + } +} + +location @null_data { + default_type application/json; + return 200 '{"ok": true, "data": null}'; +} + +# Deny locations containing /securage/ +location ~ /securage/ { + return 403; +} + +# Deny all unknown location +location / { + deny all; +}