Skip to content

Commit fc91f28

Browse files
authored
Merge pull request #20 from ash7594/master
Fix CORS issue when running app on browser, and add documentation
2 parents ee9677a + 9ad4afa commit fc91f28

File tree

5 files changed

+37
-0
lines changed

5 files changed

+37
-0
lines changed

README.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ When the reader has completed this Code Pattern, they will understand how to:
3939

4040
* [Whisk Deploy _(wskdeploy)_](https://github.com/apache/incubator-openwhisk-wskdeploy) is a utility to help you describe and deploy any part of the OpenWhisk programming model using a Manifest file written in YAML. You'll use it to deploy all the Cloud Function resources using a single command. You can download it from the [releases page](https://github.com/apache/incubator-openwhisk-wskdeploy/releases) and select the appropriate file for your system.
4141

42+
```
43+
brew install wskdeploy
44+
```
45+
4246
* Install [Node.js](https://nodejs.org/) if you want to use Electron.
4347

4448
# Steps
@@ -62,6 +66,14 @@ Create a [Watson Visual Recognition](https://console.bluemix.net/catalog/service
6266
* Copy the API Key in the Credentials section and paste it in the `local.env` file in the value of `WATSON_VISUAL_APIKEY`
6367

6468
### 3. Deploy Cloud Functions
69+
70+
Create 2 databases in cloudant:
71+
72+
1. images
73+
2. tags
74+
75+
![](docs/databases-cloudant.png)
76+
6577
> Choose one of the deployment methods
6678
6779
## Deploy through the IBM Cloud Functions console user interface
@@ -102,6 +114,24 @@ $ npm start
102114

103115
* _(or) Double-click `web/index.html`_
104116

117+
> When using this option, we need to enable CORS - https://cloud.ibm.com/docs/services/Cloudant/api/cors.html#cors
118+
119+
![](docs/before-cors.png)
120+
121+
Follow the below steps to enable CORS (also listed in the link above):
122+
123+
```
124+
cd web/
125+
126+
curl -X PUT -u "<CLOUDANT_USERNAME>:<CLOUDANT_PASSWORD>" -H "Content-Type: application/json" https://<CLOUDANT_USERNAME>.cloudant.com/_api/v2/user/config/cors -T cors.json
127+
128+
python3 -m http.server 8000
129+
```
130+
131+
Open browser and enter `localhost:8000` in the address bar.
132+
133+
![](docs/after-cors.png)
134+
105135
# Sample output
106136

107137
![sample-output](docs/screenshot.png)

docs/after-cors.png

621 KB
Loading

docs/before-cors.png

866 KB
Loading

docs/databases-cloudant.png

226 KB
Loading

web/cors.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"enable_cors": true,
3+
"allow_credentials": true,
4+
"origins": [
5+
"http://localhost:8000"
6+
]
7+
}

0 commit comments

Comments
 (0)