tangojs-connector-mtango

0.5.1 • Public • Published

tangojs-connector-mtango

mTango backend support for TangoJS.

Example

The module exports single constructor function, MTangoConnector. Create the connector and pass it to the setConnector method:

const connector = new window.tangojs.connector.mtango.MTangoConnector(
  'http://localhost:8080/mtango/rest/rc2', // endpoint
  'tango',                                 // username
  'tango')                                 // password
 
window.tangojs.core.setConnector(connector)

Configuration

To use this connector, CORS support must be enabled in mTango. This may be configured in your servlet container - bundled (*.jar) version of mTango won't work. Required steps are described below.

  1. Deploy mTango on Apache Tomcat, according to these instructions.

  2. Make sure everything works, e.g. you can see the list of all devices if you access http://localhost:8080/mtango/rest/rc2/devices in your browser.

  3. Shutdown the container.

  4. Modify <security-constraint> for RESTful endpoint (declared in ${CATALINA_HOME}/webapps/mtango/WEB-INF/web.xml). The constraint shall apply to all HTTP methods except OPTIONS, which is used for CORS preflight:

Tango RESTful gateway /rest/* GET HEAD POST PUT DELETE mtango-rest ```
  1. Add servlet filter for CORS requests to ${CATALINA_HOME}conf/web.xml (this should also work when added to mtango-specific web.xml).
CorsFilter org.apache.catalina.filters.CorsFilter
<init-param>
  <param-name>cors.allowed.methods</param-name>
  <param-value>GET,HEAD,POST,PUT,DELETE,OPTIONS</param-value>
</init-param>

<init-param>
  <param-name>cors.allowed.headers</param-name>
  <param-value>Origin,Accept,X-Requested-With,Content-Type,Access-Control-Request-Method,Access-Control-Request-Headers,Authorization,Accept-Encoding,Accept-Language,Access-Control-Request-Method,Cache-Control,Connection,Host,Referer,User-Agent</param-value>
</init-param>
CorsFilter /rest/* ```

Readme

Keywords

Package Sidebar

Install

npm i tangojs-connector-mtango

Weekly Downloads

0

Version

0.5.1

License

MIT

Last publish

Collaborators

  • mliszcz