From c5013103d6a81c8ad17914b0334cd1061c268af2 Mon Sep 17 00:00:00 2001 From: s-ol Date: Sun, 7 Feb 2021 13:54:20 +0100 Subject: include CORS proxy nginx config --- src/index.js | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/index.js b/src/index.js index 1169307..ba50149 100644 --- a/src/index.js +++ b/src/index.js @@ -13,6 +13,11 @@ const context = [ }, ]; + +const corsOrigin = process.env.CORS_ORIGIN || location.origin; +console.log(corsOrigin); +const cors = (url) => `${corsOrigin}/remote/${url}`; + function wrapCache(target) { const orig = target.descriptor.value; @@ -45,7 +50,7 @@ class GraphContainer extends Component { @wrapCache async loadCollection(id, ...args) { - const collection = await jsonld.compact(`http://localhost:8088/${id}`, context); + const collection = await jsonld.compact(cors(id), context); let items = []; const addItems = (i) => { @@ -61,11 +66,11 @@ class GraphContainer extends Component { } else { let page = collection.first; const seen = []; - while (seen.indexOf(page.id) < 0) { + while (page && seen.indexOf(page.id) < 0) { seen.push(page.id); addItems(page.items); - page = await jsonld.compact(`http://localhost:8088/${page.next}`, context); + page = page.next && await jsonld.compact(cors(page.next), context); } } @@ -76,7 +81,7 @@ class GraphContainer extends Component { @wrapCache async loadNote(id, items) { const item = await jsonld.frame( - `http://localhost:8088/${id}`, + cors(id), { '@context': context, type: 'Note', -- cgit v1.2.3