Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Dellybro committed Nov 8, 2017
1 parent db2d481 commit 02db8b5
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
43 changes: 43 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
class Fetch {
static updateConfig(urls){
this.urls = urls;
}

static request(uri, options){
// To keep fetch out of the global scope
// encourages importing this file.
require('whatwg-fetch');

let mod_uri = uri;
mod_uri = `${window.location.protocol}//${this.urls[window.location.hostname] || window.location.hostname}${uri}`;

let finalOptions = Object.assign(
{},
options,
{ credentials: 'include' }
);

return fetch(mod_uri, finalOptions);
}
static getServerURL() {
return `${window.location.protocol}//${this.urls[window.location.hostname] || window.location.hostname}`;
}
}

Fetch.urls = {
localhost: "localhost:3000"
}

function request(uri, options) {
return Fetch.request(uri, options)
}

function updateFetchConfig(urls){
Fetch.updateConfig(urls);
}

module.exports = {
Fetch: Fetch,
updateFetchConfig: updateFetchConfig,
fetch: request
}
15 changes: 15 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "@fyresite/fetch",
"version": "1.0.4",
"description": "Uses whatWG-fetch to provide an easier way to send api requests",
"main": "index.js",
"dependencies": {
"whatwg-fetch": "^2.0.3"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "Fyresite",
"license": "ISC",
"private": false
}

0 comments on commit 02db8b5

Please sign in to comment.