generated from cloud-gov/.github
-
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.
Merge pull request #23 from cloud-gov/jvd/local-token
Small app testing ability to use cf token for local development
- Loading branch information
Showing
7 changed files
with
1,281 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 @@ | ||
node_modules |
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,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. |
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,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 }; |
Oops, something went wrong.