Skip to content

Commit

Permalink
Add support for http protocol requests
Browse files Browse the repository at this point in the history
  • Loading branch information
nechaido committed Jun 18, 2021
1 parent c9dc8cb commit c27a016
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## [Unreleased][unreleased]

- Add support for `http ` protocol requests

## [1.7.3][] - 2021-06-08

- Fix passing validation error to the client
Expand Down
4 changes: 3 additions & 1 deletion lib/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ const fetch = (url, options) => {
});
};

const isProtocolSecure = (protocol) => !['ws:', 'http:'].includes(protocol);

class Metacom extends EventEmitter {
constructor(url) {
super();
Expand Down Expand Up @@ -92,7 +94,7 @@ class Metacom extends EventEmitter {
const target = interfaceName + '/' + methodName;
const packet = { call: callId, [target]: args };
const dest = new URL(this.url);
const protocol = dest.protocol === 'ws:' ? 'http' : 'https';
const protocol = isProtocolSecure(dest.protocol) ? 'https' : 'http';
const url = `${protocol}://${dest.host}/api`;
return fetch(url, {
method: 'POST',
Expand Down

0 comments on commit c27a016

Please sign in to comment.