appbaseio / appbase-js

appbase.io search client library for JavaScript
MIT License
42 stars 18 forks source link

Allow plain path for url #48

Closed focusaurus closed 2 years ago

focusaurus commented 5 years ago

I would like to configure an elasticsearch URL of just "/elasticsearch" and allow my server to reverse proxy the HTTP traffic to elasticsearch. Currently the configuration validation code requires the configured URL to include the protocol. This creates a configuration and CORS problem I would like to avoid in the browser by just talking to my main app server and proxying from there. I have so far not found a way to do this due to this validation.

Error: Protocol is not present in url. URL should be of the form https://scalr.api.appbase.io

appbase-js.es.js:128
AppBase appbase-js.es.js:128
index appbase-js.es.js:904
setStore ReactiveBase.js:155
ReactiveBase ReactiveBase.js:67
constructClassInstance23React
metagrover commented 5 years ago

I guess we can remove host+domain validations for non-appbase url(s). What do you think @siddharthlatest @bietkul?

tankchintan commented 4 years ago

I am also facing this exact same issue when I turned on proxy in package.json. @metagrover @bietkul

@focusaurus were you able to resolve this somehow?

zguillen commented 4 years ago

I had exact same issue when using proxy via package.json. This is a silly workaround but works for me, hopefully it'll help you guys out:

// reactive search won't allow relative url, so re-construct:
const port = window.location.port ? `:${window.location.port}` : '';
const url = `${window.location.protocol}//${window.location.hostname}${port}/api`;
return (
  <SearchContent className={searchStyle}>
    <ReactiveBase
      app="datasets"
      url={url}
      headers={
        {'x-csrf-token': getToken()}
      }
    >
danielnolde commented 4 years ago

What about the state of this? Just ran into the same CORS problem which could only be solved via a vue server proxy configuration if SearchBase.url would accept a relative uri like "/endpoint".