Skip to content

Commit

Permalink
refactor: changed the way we handle api key and added a proxy mode
Browse files Browse the repository at this point in the history
BREAKING CHANGES:

You have to remove your api key from the `forRoot` call and use proxy url if you want to use one.
  • Loading branch information
Supamiu committed Mar 27, 2019
1 parent b1d8e39 commit 5a28752
Show file tree
Hide file tree
Showing 8 changed files with 221 additions and 161 deletions.
15 changes: 15 additions & 0 deletions CHANGELOG.md
Expand Up @@ -2,6 +2,21 @@

All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.

<a name="0.10.7"></a>
## [0.10.7](https://github.com/xivapi/angular-client/compare/v0.10.6...v0.10.7) (2019-03-27)


### Code Refactoring

* changed the way we handle api key and added a proxy mode ([a1d6843](https://github.com/xivapi/angular-client/commit/a1d6843))


### BREAKING CHANGES

* You have to remove your api key from the `forRoot` call and use proxy url if you want to use one.



<a name="0.10.6"></a>
## [0.10.6](https://github.com/xivapi/angular-client/compare/v0.10.4...v0.10.6) (2018-12-23)

Expand Down
39 changes: 38 additions & 1 deletion README.md
Expand Up @@ -24,7 +24,7 @@ Add `XivapiClientModule` to your `AppModule` imports:
],
imports: [
...
XivapiClientModule.forRoot('my-api-key'),
XivapiClientModule.forRoot(),
...
],
bootstrap: [AppComponent]
Expand All @@ -50,3 +50,40 @@ export class FooComponent {
}
}
```

## Use with private_key (Google Cloud Function)

- Create a google cloud function, name it as you want.
- Insert following code (with your key):
```js
exports.xivapiProxy = (req, res) => {
let request = require('request');
const apiKey = '<your api key>>';
res.set('Access-Control-Allow-Origin', '<your allowed origins>')
.set('Access-Control-Allow-Headers', 'Content-Type');
const url = Buffer.from(req.query.url, 'base64').toString();
request(
{
url:`${url}${url.indexOf('?') > -1 ? '&':'?'}private_key=${apiKey}`,
},
function(error, response, body) {
let errorBody = JSON.parse(body);
let errorMessage = errorBody.error || errorBody.message;
if (error || errorMessage) {
res.status(400).send(errorMessage || 'Unknown Error');
} else {
res.status(200).set('Content-Type', 'application/json').send(body);
}
});
};
```
- Enable proxy mode inside the api module:
```ts
XivapiClientModule.forRoot('<GCF trigger url>')
```

Example url: https://us-central1-myproject.cloudfunctions.net/xivapi-proxy

Keep in mind that you can enable it based on the current environment, simply give `null` as proxy url if environment isn't prod,
to use "normal" mode in order to get better debugging
when using dev environment.

0 comments on commit 5a28752

Please sign in to comment.