Skip to content

Commit

Permalink
Merge pull request #23 from cloud-gov/jvd/local-token
Browse files Browse the repository at this point in the history
Small app testing ability to use cf token for local development
  • Loading branch information
jduss4 authored Feb 29, 2024
2 parents 7b4edd4 + 80c01c0 commit b9fa819
Show file tree
Hide file tree
Showing 7 changed files with 1,281 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
18 changes: 18 additions & 0 deletions local-dev/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Local dev testing

Log into an actual cloud.gov endpoint:

```bash
# production
cf login -a api.fr.cloud.gov --sso
```

Start the application for local dev and pass in your CF token:

```bash
CF_USER_TOKEN=$(cf oauth-token) npm run local
```

Open the app at `localhost:8000` and you should see a short list of applications you have access to in CF, and their current state.

If you start to get authentication errors in the console, you may need to restart the server to get it the latest and greatest token.
26 changes: 26 additions & 0 deletions local-dev/api.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/***/
// API library for basic error handling and serialization
/***/

async function getData(url, token) {
try {
const res = await fetch(url, {
method: "GET",
headers: {
"Authorization": token
}
});
if (res.ok) {
const data = await res.json();
return data;
} else {
const data = await res.json();
console.log("ERROR " + JSON.stringify(data));
throw new Error(`an error occurred with response code ${res.status}`);
}
} catch (error) {
throw new Error(error.message);
}
};

module.exports = { getData };
Loading

0 comments on commit b9fa819

Please sign in to comment.