Skip to content
This repository has been archived by the owner on Mar 13, 2024. It is now read-only.

Commit

Permalink
Nodejs support (#232)
Browse files Browse the repository at this point in the history
* allow test server to be set via env.
this allows running the unit tests against a mattermost server running somewhere other than 127.0.0.1.
e.g. MATTERMOST_SERVER_URL="http:https://mattermost:8065" npm run test

* disable eslint no-process-env check

* fix building for node.js
add the transform-runtime babel plugin to allow generated client to run in node.js

* add websocket to index.js
just for completeness and making it easier to access all javascript APIs from one place.

* document node.js example usage

* peg babel-plugin-transform-runtime to a specific version

* Revert "disable eslint no-process-env check"

This reverts commit cb3a313fc82e2857f200c79035ddee2ed0e9b6cc.

* Revert "allow test server to be set via env."

This reverts commit 19b56c69d81627d52ff6c4a87eaa38528eb53021.

* Revert "fix building for node.js"

This reverts commit 2834deb0b9b1a51af16e22e8aa80029ff638de83.

* Revert "add websocket to index.js"

This reverts commit 23c9ff60b5ed1cd2dd9561b32a6709900d3e22b2.

* update nodejs example to use client4 and websocket_client directly
  • Loading branch information
brettmc authored and enahum committed Aug 18, 2017
1 parent f410a76 commit c5a9c96
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,39 @@ Client4.setUrl('https://your-mattermost-url.com');
Client4.setToken(yourToken);
```

### node.js Usage

Running the client from node.js requires making the `fetch` and `WebSocket` packages globally available, and the use of `babel-polyfill`:

```
require('babel-polyfill');
require('isomorphic-fetch');
if (!global.WebSocket) {
global.WebSocket = require('ws');
}
const Client4 = require('./client/client4.js').default;
const client = new Client4;
const wsClient = require('./client/websocket_client.js').default;
var token;
wsClient.setEventCallback(function(event){
console.log(event);
});
client.setUrl('https://your-mattermost-url.com');
client.login(username, password)
.then(function(me){
console.log(`logged in as ${me.email}`);
token = client.getToken();
})
.then(function(){
wsClient.initialize(token, {}, {}, {connectionUrl: 'wss:https://your-mattermost-url.com/api/v4/websocket'});
})
.catch(function(err){
console.error(err);
});
```

# Features for Stable Release

* Improved return pattern for actions, always return both data and error
Expand Down

0 comments on commit c5a9c96

Please sign in to comment.