This repository has been archived by the owner on Nov 14, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
74 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
{ | ||
"presets": ["es2015"] | ||
"presets": ["es2015"], | ||
"plugins": ["transform-object-rest-spread"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
'use strict'; | ||
|
||
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; | ||
|
||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = fetch; | ||
exports.post = post; | ||
|
||
var _isomorphicFetch = require('isomorphic-fetch'); | ||
|
||
var _isomorphicFetch2 = _interopRequireDefault(_isomorphicFetch); | ||
|
||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
|
||
var JSON_HEADERS = { | ||
Accept: 'application/json', | ||
'Content-Type': 'application/json' | ||
}; | ||
|
||
var BASE_URL = process.env.BASE_URL || 'https://player.me/api/v1'; | ||
|
||
console.log(BASE_URL); | ||
function fetch(endpoint) { | ||
var config = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1]; | ||
|
||
var url = BASE_URL + '/' + endpoint; | ||
|
||
return (0, _isomorphicFetch2.default)(url, _extends({ | ||
headers: JSON_HEADERS, | ||
method: 'GET' | ||
}, config)).then(function (response) { | ||
return response.json(); | ||
}); | ||
} | ||
|
||
function post(endpoint, args) { | ||
return fetch(endpoint, { method: 'POST', body: JSON.stringify(args) }); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import _fetch from 'isomorphic-fetch'; | ||
|
||
const JSON_HEADERS = { | ||
Accept: 'application/json', | ||
'Content-Type': 'application/json' | ||
}; | ||
|
||
const BASE_URL = process.env.BASE_URL || 'https://player.me/api/v1'; | ||
|
||
export default function fetch(endpoint, config = {}) { | ||
const url = `${BASE_URL}/${endpoint}`; | ||
|
||
return _fetch( | ||
url, { | ||
headers: JSON_HEADERS, | ||
method: 'GET', | ||
...config | ||
} | ||
).then(response => response.json()); | ||
} | ||
|
||
export function post(endpoint, args) { | ||
return fetch(endpoint, { method: 'POST', body: JSON.stringify(args) }); | ||
} |