nuxeo / nuxeo-js-client

JavaScript client library for Nuxeo API
Other
18 stars 20 forks source link

Unable to connect by 'nuxeo.connect' method #97

Closed i10111pn closed 4 years ago

i10111pn commented 4 years ago

Hi.

I have a react application that is trying to connect to the nuxeo ui. Nuxeo is launched by a docker command:

docker run --name mynuxeo --rm -ti -p 8080:8080 -e NUXEO_PACKAGES="nuxeo-web-ui nuxeo-showcase-content nuxeo-template-rendering nuxeo-template-rendering-samples" -e NUXEO_CUSTOM_PARAM="org.nuxeo.dev=true\nallowOrigin=http://localhost:3000\nallowSubdomains=true\nsupportedMethods=GET,POST,HEAD,OPTIONS" nuxeo:9.10

and accessible in the browser at http://172.17.0.2:8080/nuxeo/ or http://localhost:8080/nuxeo/.

The react application is created by create-react-app. My package.json:

{
  "name": "react-nuxeo",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@testing-library/jest-dom": "^4.2.4",
    "@testing-library/react": "^9.4.0",
    "@testing-library/user-event": "^7.1.2",
    "nuxeo": "^3.15.0",
    "react": "^16.12.0",
    "react-dom": "^16.12.0",
    "react-router-dom": "^5.1.2",
    "react-scripts": "^3.3.0"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },
  "eslintConfig": {
    "extends": "react-app"
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  }
}

Inside of the react application, I have the next code:

  let nuxeo = new Nuxeo({
      baseURL: 'http://172.17.0.2:8080/nuxeo',
      auth: {
        method: 'basic',
        username: 'Administrator',
        password: 'Administrator'
      }
    });

    nuxeo.connect({
      mode: 'no-cors',
      headers: {
        'Access-Control-Allow-Origin': '*'
      }
    })
      .then((client) => this.setState({ nuxeo_status: 'connected' }))
      .catch((error) => this.setState({ nuxeo_status: 'error' }));

Which is producing the next error:

image

Request params are next:

image

Is there a way to fix this?

i10111pn commented 4 years ago

Launching docker image with cors config file fixed the issue.

docker run --name mynuxeo --user nuxeo:nuxeo --mount type=bind,source="/home/i10111pn/Configs/cors-config.xml",target=/opt/nuxeo/server/templates/docker/config/cors-config.xml.nxftl --rm -ti -p 8080:8080 -e NUXEO_PACKAGES="nuxeo-web-ui" nuxeo:9.10

Where cors-config.xml:

<component name="org.nuxeo.cors.config">
  <extension target="org.nuxeo.ecm.platform.web.common.requestcontroller.service.RequestControllerService" point="corsConfig">
    <corsConfig name="all" supportedMethods ="GET,POST,HEAD,OPTIONS,DELETE,PUT">
      <pattern>/nuxeo/.*</pattern>
    </corsConfig>
  </extension>
</component>