From 47890ad56eaa7b25b45e52d57ae4734b6d5389d5 Mon Sep 17 00:00:00 2001 From: Mark Beamer Jr Date: Sun, 8 Apr 2018 02:13:27 -0400 Subject: [PATCH] Updated API docs to fix documentation errors on github pages which is the target of the documentation. The main culprit was not having cors enabled to handle the same origin policy of the browsers. With the koa-cors package now enabled this will work perfectly. --- apidoc.json | 6 +- docs/api_data.js | 190 +----------------------------- docs/api_data.json | 190 +----------------------------- docs/api_project.js | 22 +--- docs/api_project.json | 22 +--- docs/utils/send_sample_request.js | 0 package.json | 1 + server/index.js | 4 +- 8 files changed, 11 insertions(+), 424 deletions(-) mode change 100644 => 100755 docs/utils/send_sample_request.js diff --git a/apidoc.json b/apidoc.json index 0d9990b..5cd2681 100644 --- a/apidoc.json +++ b/apidoc.json @@ -3,11 +3,11 @@ "version": "0.0.1", "description": "Lighthouse - Next-gen search api for LBRY", "title": "Lighthouse API DOCS", - "url" : "http://localhost", - "sampleUrl": "http://localhost", + "url" : "http://lighthouse.lbry.io", + "sampleUrl": "http://lighthouse.lbry.io", "json_body": true, "template": { "withCompare": true, "withGenerator": true } -} \ No newline at end of file +} diff --git a/docs/api_data.js b/docs/api_data.js index 2742711..301e548 100644 --- a/docs/api_data.js +++ b/docs/api_data.js @@ -1,189 +1 @@ -define({ "api": [ - { - "type": "get", - "url": "/autocomplete", - "title": "Autocomplete API", - "group": "Search", - "parameter": { - "fields": { - "Parameter": [ - { - "group": "Parameter", - "type": "String", - "optional": false, - "field": "s", - "description": "

The text to be autocompleted (Required).

" - } - ] - }, - "examples": [ - { - "title": "Example", - "content": "http://localhost/autocomplete?s=fillerino", - "type": "url" - } - ] - }, - "success": { - "fields": { - "Success 200": [ - { - "group": "Success 200", - "type": "Array[]", - "optional": false, - "field": "array", - "description": "

List of search response, each containing the value below.

" - } - ] - }, - "examples": [ - { - "title": "Success", - "content": "HTTP/1.1 200 OK\n\n[\"@Fillerino\",\"fillerino-js-test\",\"Text Javascript Injection\"]", - "type": "json" - } - ] - }, - "version": "0.0.0", - "filename": "server/routes/lighthouse.js", - "groupTitle": "Search", - "name": "GetAutocomplete", - "sampleRequest": [ - { - "url": "http://localhost/autocomplete" - } - ] - }, - { - "type": "get", - "url": "/search", - "title": "Main Search API", - "group": "Search", - "parameter": { - "fields": { - "Parameter": [ - { - "group": "Parameter", - "type": "String", - "optional": false, - "field": "s", - "description": "

The search text (Required)

" - }, - { - "group": "Parameter", - "type": "Integer", - "optional": false, - "field": "size", - "description": "

Amount of results to return as max

" - }, - { - "group": "Parameter", - "type": "Integer", - "optional": false, - "field": "from", - "description": "

The number to start from, good for pagination.

" - } - ] - }, - "examples": [ - { - "title": "Example", - "content": "http://localhost/search?s=fillerino", - "type": "url" - } - ] - }, - "success": { - "fields": { - "Success 200": [ - { - "group": "Success 200", - "type": "Array[]", - "optional": false, - "field": "array", - "description": "

List of search response, each containing the value below.

" - }, - { - "group": "Success 200", - "type": "Object[]", - "optional": false, - "field": "result", - "description": "

A search result

" - }, - { - "group": "Success 200", - "type": "String", - "optional": false, - "field": "result.name", - "description": "

The name of the claim.

" - }, - { - "group": "Success 200", - "type": "String", - "optional": false, - "field": "result.claimId", - "description": "

The claimId of the claim.

" - }, - { - "group": "Success 200", - "type": "Object[]", - "optional": false, - "field": "result.value", - "description": "

The decoded value of the metadata

" - } - ] - }, - "examples": [ - { - "title": "Success", - "content": " HTTP/1.1 200 OK\n[\n {\n \"name\":\"fillerino-js-test\",\n \"claimId\":\"7bfed722c678a0e0ceb9fb90974bfcc65f528813\",\n \"value\":{\n \"version\":\"_0_0_1\",\n \"claimType\":\"streamType\",\n \"stream\":{\n \"source\":{\n \"source\":\"7ded8c9c7527fce26ced886adcd2eab9fc424c0126eff6572f0615ab66ec3bfbdbbfc1603d95cecd81c9b93fa8ecfbf8\",\n \"version\":\"_0_0_1\",\n \"contentType\":\"text/html\",\n \"sourceType\":\"lbry_sd_hash\"\n },\n \"version\":\"_0_0_1\",\n \"metadata\":{\n \"license\":\"Public Domain\",\n \"description\":\"A test file which tries to communicate with the daemon(from inside the app).\",\n \"language\":\"en\",\n \"title\":\"Text Javascript Injection\",\n \"author\":\"\",\n \"version\":\"_0_1_0\",\n \"nsfw\":false,\n \"licenseUrl\":\"\",\n \"preview\":\"\",\n \"thumbnail\":\"\"\n }\n }\n }\n },\n {...},\n {...}\n]", - "type": "json" - } - ] - }, - "version": "0.0.0", - "filename": "server/routes/lighthouse.js", - "groupTitle": "Search", - "name": "GetSearch", - "sampleRequest": [ - { - "url": "http://localhost/search" - } - ] - }, - { - "type": "get", - "url": "/status", - "title": "Status", - "group": "Search", - "success": { - "fields": { - "Success 200": [ - { - "group": "Success 200", - "type": "Array[]", - "optional": false, - "field": "array", - "description": "

Will contain information about lighthouse.

" - } - ] - }, - "examples": [ - { - "title": "Success", - "content": "HTTP/1.1 200 OK\n\n{\"err\": \"Not done yet, will be added\"}", - "type": "json" - } - ] - }, - "version": "0.0.0", - "filename": "server/routes/lighthouse.js", - "groupTitle": "Search", - "name": "GetStatus", - "sampleRequest": [ - { - "url": "http://localhost/status" - } - ] - } -] }); +define({ "api": [ { "type": "get", "url": "/autocomplete", "title": "Autocomplete API", "group": "Search", "parameter": { "fields": { "Parameter": [ { "group": "Parameter", "type": "String", "optional": false, "field": "s", "description": "

The text to be autocompleted (Required).

" } ] }, "examples": [ { "title": "Example", "content": "http://localhost/autocomplete?s=fillerino", "type": "url" } ] }, "success": { "fields": { "Success 200": [ { "group": "Success 200", "type": "Array[]", "optional": false, "field": "array", "description": "

List of search response, each containing the value below.

" } ] }, "examples": [ { "title": "Success", "content": "HTTP/1.1 200 OK\n\n[\"@Fillerino\",\"fillerino-js-test\",\"Text Javascript Injection\"]", "type": "json" } ] }, "version": "0.0.0", "filename": "server/routes/lighthouse.js", "groupTitle": "Search", "name": "GetAutocomplete", "sampleRequest": [ { "url": "http://lighthouse.lbry.io/autocomplete" } ] }, { "type": "get", "url": "/search", "title": "Main Search API", "group": "Search", "parameter": { "fields": { "Parameter": [ { "group": "Parameter", "type": "String", "optional": false, "field": "s", "description": "

The search text (Required)

" }, { "group": "Parameter", "type": "Integer", "optional": false, "field": "size", "description": "

Amount of results to return as max

" }, { "group": "Parameter", "type": "Integer", "optional": false, "field": "from", "description": "

The number to start from, good for pagination.

" } ] }, "examples": [ { "title": "Example", "content": "http://localhost/search?s=fillerino", "type": "url" } ] }, "success": { "fields": { "Success 200": [ { "group": "Success 200", "type": "Array[]", "optional": false, "field": "array", "description": "

List of search response, each containing the value below.

" }, { "group": "Success 200", "type": "Object[]", "optional": false, "field": "result", "description": "

A search result

" }, { "group": "Success 200", "type": "String", "optional": false, "field": "result.name", "description": "

The name of the claim.

" }, { "group": "Success 200", "type": "String", "optional": false, "field": "result.claimId", "description": "

The claimId of the claim.

" }, { "group": "Success 200", "type": "Object[]", "optional": false, "field": "result.value", "description": "

The decoded value of the metadata

" } ] }, "examples": [ { "title": "Success", "content": " HTTP/1.1 200 OK\n[\n {\n \"name\":\"fillerino-js-test\",\n \"claimId\":\"7bfed722c678a0e0ceb9fb90974bfcc65f528813\",\n \"value\":{\n \"version\":\"_0_0_1\",\n \"claimType\":\"streamType\",\n \"stream\":{\n \"source\":{\n \"source\":\"7ded8c9c7527fce26ced886adcd2eab9fc424c0126eff6572f0615ab66ec3bfbdbbfc1603d95cecd81c9b93fa8ecfbf8\",\n \"version\":\"_0_0_1\",\n \"contentType\":\"text/html\",\n \"sourceType\":\"lbry_sd_hash\"\n },\n \"version\":\"_0_0_1\",\n \"metadata\":{\n \"license\":\"Public Domain\",\n \"description\":\"A test file which tries to communicate with the daemon(from inside the app).\",\n \"language\":\"en\",\n \"title\":\"Text Javascript Injection\",\n \"author\":\"\",\n \"version\":\"_0_1_0\",\n \"nsfw\":false,\n \"licenseUrl\":\"\",\n \"preview\":\"\",\n \"thumbnail\":\"\"\n }\n }\n }\n },\n {...},\n {...}\n]", "type": "json" } ] }, "version": "0.0.0", "filename": "server/routes/lighthouse.js", "groupTitle": "Search", "name": "GetSearch", "sampleRequest": [ { "url": "http://lighthouse.lbry.io/search" } ] }, { "type": "get", "url": "/status", "title": "Status", "group": "Search", "success": { "fields": { "Success 200": [ { "group": "Success 200", "type": "Array[]", "optional": false, "field": "array", "description": "

Will contain information about lighthouse.

" } ] }, "examples": [ { "title": "Success", "content": "HTTP/1.1 200 OK\n\n{\"err\": \"Not done yet, will be added\"}", "type": "json" } ] }, "version": "0.0.0", "filename": "server/routes/lighthouse.js", "groupTitle": "Search", "name": "GetStatus", "sampleRequest": [ { "url": "http://lighthouse.lbry.io/status" } ] } ] }); diff --git a/docs/api_data.json b/docs/api_data.json index e43bd35..36f3c90 100644 --- a/docs/api_data.json +++ b/docs/api_data.json @@ -1,189 +1 @@ -[ - { - "type": "get", - "url": "/autocomplete", - "title": "Autocomplete API", - "group": "Search", - "parameter": { - "fields": { - "Parameter": [ - { - "group": "Parameter", - "type": "String", - "optional": false, - "field": "s", - "description": "

The text to be autocompleted (Required).

" - } - ] - }, - "examples": [ - { - "title": "Example", - "content": "http://localhost/autocomplete?s=fillerino", - "type": "url" - } - ] - }, - "success": { - "fields": { - "Success 200": [ - { - "group": "Success 200", - "type": "Array[]", - "optional": false, - "field": "array", - "description": "

List of search response, each containing the value below.

" - } - ] - }, - "examples": [ - { - "title": "Success", - "content": "HTTP/1.1 200 OK\n\n[\"@Fillerino\",\"fillerino-js-test\",\"Text Javascript Injection\"]", - "type": "json" - } - ] - }, - "version": "0.0.0", - "filename": "server/routes/lighthouse.js", - "groupTitle": "Search", - "name": "GetAutocomplete", - "sampleRequest": [ - { - "url": "http://localhost/autocomplete" - } - ] - }, - { - "type": "get", - "url": "/search", - "title": "Main Search API", - "group": "Search", - "parameter": { - "fields": { - "Parameter": [ - { - "group": "Parameter", - "type": "String", - "optional": false, - "field": "s", - "description": "

The search text (Required)

" - }, - { - "group": "Parameter", - "type": "Integer", - "optional": false, - "field": "size", - "description": "

Amount of results to return as max

" - }, - { - "group": "Parameter", - "type": "Integer", - "optional": false, - "field": "from", - "description": "

The number to start from, good for pagination.

" - } - ] - }, - "examples": [ - { - "title": "Example", - "content": "http://localhost/search?s=fillerino", - "type": "url" - } - ] - }, - "success": { - "fields": { - "Success 200": [ - { - "group": "Success 200", - "type": "Array[]", - "optional": false, - "field": "array", - "description": "

List of search response, each containing the value below.

" - }, - { - "group": "Success 200", - "type": "Object[]", - "optional": false, - "field": "result", - "description": "

A search result

" - }, - { - "group": "Success 200", - "type": "String", - "optional": false, - "field": "result.name", - "description": "

The name of the claim.

" - }, - { - "group": "Success 200", - "type": "String", - "optional": false, - "field": "result.claimId", - "description": "

The claimId of the claim.

" - }, - { - "group": "Success 200", - "type": "Object[]", - "optional": false, - "field": "result.value", - "description": "

The decoded value of the metadata

" - } - ] - }, - "examples": [ - { - "title": "Success", - "content": " HTTP/1.1 200 OK\n[\n {\n \"name\":\"fillerino-js-test\",\n \"claimId\":\"7bfed722c678a0e0ceb9fb90974bfcc65f528813\",\n \"value\":{\n \"version\":\"_0_0_1\",\n \"claimType\":\"streamType\",\n \"stream\":{\n \"source\":{\n \"source\":\"7ded8c9c7527fce26ced886adcd2eab9fc424c0126eff6572f0615ab66ec3bfbdbbfc1603d95cecd81c9b93fa8ecfbf8\",\n \"version\":\"_0_0_1\",\n \"contentType\":\"text/html\",\n \"sourceType\":\"lbry_sd_hash\"\n },\n \"version\":\"_0_0_1\",\n \"metadata\":{\n \"license\":\"Public Domain\",\n \"description\":\"A test file which tries to communicate with the daemon(from inside the app).\",\n \"language\":\"en\",\n \"title\":\"Text Javascript Injection\",\n \"author\":\"\",\n \"version\":\"_0_1_0\",\n \"nsfw\":false,\n \"licenseUrl\":\"\",\n \"preview\":\"\",\n \"thumbnail\":\"\"\n }\n }\n }\n },\n {...},\n {...}\n]", - "type": "json" - } - ] - }, - "version": "0.0.0", - "filename": "server/routes/lighthouse.js", - "groupTitle": "Search", - "name": "GetSearch", - "sampleRequest": [ - { - "url": "http://localhost/search" - } - ] - }, - { - "type": "get", - "url": "/status", - "title": "Status", - "group": "Search", - "success": { - "fields": { - "Success 200": [ - { - "group": "Success 200", - "type": "Array[]", - "optional": false, - "field": "array", - "description": "

Will contain information about lighthouse.

" - } - ] - }, - "examples": [ - { - "title": "Success", - "content": "HTTP/1.1 200 OK\n\n{\"err\": \"Not done yet, will be added\"}", - "type": "json" - } - ] - }, - "version": "0.0.0", - "filename": "server/routes/lighthouse.js", - "groupTitle": "Search", - "name": "GetStatus", - "sampleRequest": [ - { - "url": "http://localhost/status" - } - ] - } -] +[ { "type": "get", "url": "/autocomplete", "title": "Autocomplete API", "group": "Search", "parameter": { "fields": { "Parameter": [ { "group": "Parameter", "type": "String", "optional": false, "field": "s", "description": "

The text to be autocompleted (Required).

" } ] }, "examples": [ { "title": "Example", "content": "http://localhost/autocomplete?s=fillerino", "type": "url" } ] }, "success": { "fields": { "Success 200": [ { "group": "Success 200", "type": "Array[]", "optional": false, "field": "array", "description": "

List of search response, each containing the value below.

" } ] }, "examples": [ { "title": "Success", "content": "HTTP/1.1 200 OK\n\n[\"@Fillerino\",\"fillerino-js-test\",\"Text Javascript Injection\"]", "type": "json" } ] }, "version": "0.0.0", "filename": "server/routes/lighthouse.js", "groupTitle": "Search", "name": "GetAutocomplete", "sampleRequest": [ { "url": "http://lighthouse.lbry.io/autocomplete" } ] }, { "type": "get", "url": "/search", "title": "Main Search API", "group": "Search", "parameter": { "fields": { "Parameter": [ { "group": "Parameter", "type": "String", "optional": false, "field": "s", "description": "

The search text (Required)

" }, { "group": "Parameter", "type": "Integer", "optional": false, "field": "size", "description": "

Amount of results to return as max

" }, { "group": "Parameter", "type": "Integer", "optional": false, "field": "from", "description": "

The number to start from, good for pagination.

" } ] }, "examples": [ { "title": "Example", "content": "http://localhost/search?s=fillerino", "type": "url" } ] }, "success": { "fields": { "Success 200": [ { "group": "Success 200", "type": "Array[]", "optional": false, "field": "array", "description": "

List of search response, each containing the value below.

" }, { "group": "Success 200", "type": "Object[]", "optional": false, "field": "result", "description": "

A search result

" }, { "group": "Success 200", "type": "String", "optional": false, "field": "result.name", "description": "

The name of the claim.

" }, { "group": "Success 200", "type": "String", "optional": false, "field": "result.claimId", "description": "

The claimId of the claim.

" }, { "group": "Success 200", "type": "Object[]", "optional": false, "field": "result.value", "description": "

The decoded value of the metadata

" } ] }, "examples": [ { "title": "Success", "content": " HTTP/1.1 200 OK\n[\n {\n \"name\":\"fillerino-js-test\",\n \"claimId\":\"7bfed722c678a0e0ceb9fb90974bfcc65f528813\",\n \"value\":{\n \"version\":\"_0_0_1\",\n \"claimType\":\"streamType\",\n \"stream\":{\n \"source\":{\n \"source\":\"7ded8c9c7527fce26ced886adcd2eab9fc424c0126eff6572f0615ab66ec3bfbdbbfc1603d95cecd81c9b93fa8ecfbf8\",\n \"version\":\"_0_0_1\",\n \"contentType\":\"text/html\",\n \"sourceType\":\"lbry_sd_hash\"\n },\n \"version\":\"_0_0_1\",\n \"metadata\":{\n \"license\":\"Public Domain\",\n \"description\":\"A test file which tries to communicate with the daemon(from inside the app).\",\n \"language\":\"en\",\n \"title\":\"Text Javascript Injection\",\n \"author\":\"\",\n \"version\":\"_0_1_0\",\n \"nsfw\":false,\n \"licenseUrl\":\"\",\n \"preview\":\"\",\n \"thumbnail\":\"\"\n }\n }\n }\n },\n {...},\n {...}\n]", "type": "json" } ] }, "version": "0.0.0", "filename": "server/routes/lighthouse.js", "groupTitle": "Search", "name": "GetSearch", "sampleRequest": [ { "url": "http://lighthouse.lbry.io/search" } ] }, { "type": "get", "url": "/status", "title": "Status", "group": "Search", "success": { "fields": { "Success 200": [ { "group": "Success 200", "type": "Array[]", "optional": false, "field": "array", "description": "

Will contain information about lighthouse.

" } ] }, "examples": [ { "title": "Success", "content": "HTTP/1.1 200 OK\n\n{\"err\": \"Not done yet, will be added\"}", "type": "json" } ] }, "version": "0.0.0", "filename": "server/routes/lighthouse.js", "groupTitle": "Search", "name": "GetStatus", "sampleRequest": [ { "url": "http://lighthouse.lbry.io/status" } ] } ] diff --git a/docs/api_project.js b/docs/api_project.js index 9629784..341d6e9 100644 --- a/docs/api_project.js +++ b/docs/api_project.js @@ -1,21 +1 @@ -define({ - "name": "Lighthouse", - "version": "0.0.1", - "description": "Lighthouse - Next-gen search api for LBRY", - "title": "Lighthouse API DOCS", - "url": "http://localhost", - "sampleUrl": "http://localhost", - "json_body": true, - "template": { - "withCompare": true, - "withGenerator": true - }, - "defaultVersion": "0.0.0", - "apidoc": "0.3.0", - "generator": { - "name": "apidoc", - "time": "2017-09-28T20:35:05.906Z", - "url": "http://apidocjs.com", - "version": "0.17.6" - } -}); +define({ "name": "Lighthouse", "version": "0.0.1", "description": "Lighthouse - Next-gen search api for LBRY", "title": "Lighthouse API DOCS", "url": "http://lighthouse.lbry.io", "sampleUrl": "http://lighthouse.lbry.io", "json_body": true, "template": { "withCompare": true, "withGenerator": true }, "defaultVersion": "0.0.0", "apidoc": "0.3.0", "generator": { "name": "apidoc", "time": "2018-04-08T06:08:09.948Z", "url": "http://apidocjs.com", "version": "0.17.6" } }); diff --git a/docs/api_project.json b/docs/api_project.json index f3295df..10f635f 100644 --- a/docs/api_project.json +++ b/docs/api_project.json @@ -1,21 +1 @@ -{ - "name": "Lighthouse", - "version": "0.0.1", - "description": "Lighthouse - Next-gen search api for LBRY", - "title": "Lighthouse API DOCS", - "url": "http://localhost", - "sampleUrl": "http://localhost", - "json_body": true, - "template": { - "withCompare": true, - "withGenerator": true - }, - "defaultVersion": "0.0.0", - "apidoc": "0.3.0", - "generator": { - "name": "apidoc", - "time": "2017-09-28T20:35:05.906Z", - "url": "http://apidocjs.com", - "version": "0.17.6" - } -} +{ "name": "Lighthouse", "version": "0.0.1", "description": "Lighthouse - Next-gen search api for LBRY", "title": "Lighthouse API DOCS", "url": "http://lighthouse.lbry.io", "sampleUrl": "http://lighthouse.lbry.io", "json_body": true, "template": { "withCompare": true, "withGenerator": true }, "defaultVersion": "0.0.0", "apidoc": "0.3.0", "generator": { "name": "apidoc", "time": "2018-04-08T06:08:09.948Z", "url": "http://apidocjs.com", "version": "0.17.6" } } diff --git a/docs/utils/send_sample_request.js b/docs/utils/send_sample_request.js old mode 100644 new mode 100755 diff --git a/package.json b/package.json index cf377a2..c2c8708 100644 --- a/package.json +++ b/package.json @@ -33,6 +33,7 @@ "gendoc": "apidoc -i server/ -o docs/" }, "dependencies": { + "@koa/cors": "^2.2.1", "app-root-path": "^2.0.1", "babel-polyfill": "^6.5.0", "bitcoin-promise": "filipnyquist/node-bitcoin-promise#1fbf1cb8913ca3542b66060d48ebea185661e0a7", diff --git a/server/index.js b/server/index.js index 0d5530f..4f2c475 100644 --- a/server/index.js +++ b/server/index.js @@ -1,4 +1,5 @@ import bodyParser from 'koa-bodyparser'; +import cors from '@koa/cors'; import Koa from 'koa'; import logger from 'koa-logger'; import helmet from 'koa-helmet'; @@ -16,7 +17,8 @@ const app = new Koa(); app .use(logger()) .use(bodyParser()) - .use(helmet()); + .use(helmet()) + .use(cors()); routing(app);