@@ -15,7 +15,7 @@ function Search(event, esClient) {
1515 params = event . body
1616 }
1717
18- this . headers = event . headers
18+ this . endpoint = event . endpoint
1919
2020 this . merge = false
2121 if ( _ . has ( params , 'merge' ) ) {
@@ -34,17 +34,13 @@ function Search(event, esClient) {
3434 this . client = esClient
3535
3636 this . queries = queries ( this . params )
37-
38- console . log ( `Queries: ${ JSON . stringify ( this . queries ) } ` )
3937}
4038
4139// search for items using collection and items
42- Search . prototype . search_items = ( callback ) => {
40+ Search . prototype . search_items = function ( callback ) {
4341 // check collection first
4442 this . search_collections ( ( err , resp ) => {
4543 const collections = resp . features . map ( ( c ) => c . properties [ 'c:id' ] )
46- console . log ( 'matched collections' , collections )
47- console . log ( 'queries before' , JSON . stringify ( this . queries ) )
4844 let qs
4945 if ( collections . length === 0 ) {
5046 qs = { bool : { must_not : { exists : { field : 'c:id' } } } }
@@ -62,7 +58,7 @@ Search.prototype.search_items = (callback) => {
6258}
6359
6460
65- Search . prototype . search_collections = ( callback ) => {
61+ Search . prototype . search_collections = function ( callback ) {
6662 // hacky way to get all collections
6763 const sz = this . size
6864 const frm = this . frm
@@ -92,7 +88,7 @@ Search.prototype.search_collections = (callback) => {
9288}
9389
9490
95- Search . prototype . search = ( index , callback ) => {
91+ Search . prototype . search = function ( index , callback ) {
9692 const self = this
9793
9894 const searchParams = {
@@ -129,20 +125,15 @@ Search.prototype.search = (index, callback) => {
129125 props = _ . omit ( props , [ 'bbox' , 'geometry' , 'assets' , 'links' , 'eo:bands' ] )
130126 const links = body . hits . hits [ i ] . _source . links || [ ]
131127 // add self and collection links
132- const host = (
133- 'X-Forwarded-Host' in self . headers ?
134- self . headers [ 'X-Forwarded-Host' ] : self . headers . Host
135- )
136- const apiUrl = `${ self . headers [ 'X-Forwarded-Proto' ] } ://${ host } `
137128 let prefix = '/search/stac'
138129 if ( index === 'collections' ) {
139130 prefix = '/collections'
140- links . self = { rel : 'self' , href : `${ apiUrl } ${ prefix } ?c:id=${ props . collection } ` }
131+ links . self = { rel : 'self' , href : `${ self . endpoint } ${ prefix } ?c:id=${ props . collection } ` }
141132 }
142133 else {
143- links . self = { rel : 'self' , href : `${ apiUrl } ${ prefix } ?id=${ props . id } ` }
134+ links . self = { rel : 'self' , href : `${ self . endpoint } ${ prefix } ?id=${ props . id } ` }
144135 if ( _ . has ( props , 'c:id' ) ) {
145- links . collection = { href : `${ apiUrl } /collections/${ props [ 'c:id' ] } /definition` }
136+ links . collection = { href : `${ self . endpoint } /collections/${ props [ 'c:id' ] } /definition` }
146137 }
147138 }
148139 return {
0 commit comments