-
Notifications
You must be signed in to change notification settings - Fork 1
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
1 parent
54b7a1f
commit 9c42154
Showing
2 changed files
with
62 additions
and
0 deletions.
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 |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<doctype html> | ||
<html> | ||
<head> | ||
<meta charset="utf8"> | ||
<title>Superapi Cache test</title> | ||
|
||
<script src="../node_modules/bluebird/js/browser/bluebird.js"></script> | ||
<script src="../node_modules/localforage/dist/localforage.js"></script> | ||
<script src="../node_modules/superapi/dist/superapi.js"></script> | ||
<script src="../node_modules/superagent-dist/superagent.js"></script> | ||
<script src="../dist/superapi-cache.js"></script> | ||
<script> | ||
api = superapi.default({ | ||
baseUrl: 'http://localhost:3002', | ||
services: { | ||
person: { | ||
path: '/person/:id' | ||
} | ||
} | ||
}); | ||
api.withAgent(superagent); | ||
|
||
const superapiCache = window['superapi-cache']; | ||
|
||
localforage.setDriver([ | ||
localforage.WEBSQL, | ||
localforage.INDEXEDDB, | ||
localforage.LOCALSTORAGE | ||
]); | ||
|
||
api.register('cache', superapiCache({ | ||
store: localforage, | ||
key: function (req) { | ||
return req.url; | ||
} | ||
})); | ||
|
||
api.status(200, function (req, res) { | ||
console.log('200 called for ' + req.url); | ||
}); | ||
|
||
api.api.person({params: {id: 123456789}}) | ||
.then(function (response) { | ||
console.log(response.body); | ||
|
||
localforage.getItem('http://localhost:3002/person/123456789').then(function (value) { | ||
console.log(value); | ||
}); | ||
}) | ||
.catch(function (error) { | ||
debugger; | ||
}) | ||
|
||
</script> | ||
</head> | ||
<body> | ||
</body> | ||
</html> |
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