Skip to content

Commit 6b40ae5

Browse files
authored
[samples] Update web-workers sample (#31060)
Resolves #31049 A few changes were needed here: 1. Upgrade jsdom to >= 19 in the JS sample, similar to #20934 which fixed the TS sample 2. Update the sample to use a SAS URL so that it can be runnable 3. Remove usage of env vars, instead using the string directly and recommending passing a SAS URL from the server in production
1 parent 882ea89 commit 6b40ae5

File tree

7 files changed

+17
-23
lines changed

7 files changed

+17
-23
lines changed

samples/web-workers/README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ Before running the TypeScript samples, they must be compiled to JavaScript using
2626

2727
You need [an Azure subscription][freesub] and an Azure Storage Blob container to run this sample. Please refer to the [Storage Blob documentation][storageblob] for additional information on Azure Storage Blob.
2828

29-
To avoid complexity in this sample, we will be using a [SAS Connection String][storageblobsas] to authenticate our client. The ARM template we include will output a SAS Connection String valid for 2 hours which you can then copy and paste into the included `env` files.
29+
To avoid complexity in this sample, we will be using a [SAS URL][storageblobsas] to authenticate our client. The ARM template we include will output a SAS URL valid for 2 hours.
3030

3131
To quickly create the needed resources in Azure and to receive the necessary environment variables for them, you can deploy our sample template by clicking:
3232

@@ -36,9 +36,9 @@ Once the deployment completes, head over to the "outputs" tab and copy the outpu
3636

3737
## Running the sample
3838

39-
Once the above resources are created you'll want to ensure our application has the necessary environment variables. To do this, copy `sample.env` as `.env` and provide the necessary environment variables to configure the application. You can get the values from the output tab of the deployment.
39+
Once the above resources are created you'll want to ensure our application has the necessary values. To do this, open `workers.ts` (or `workers.js` if you are using the JavaScript sample) and set `containerSasUrl` to the generated SAS URL from the deployment. You can get that value from the output tab of the deployment.
4040

41-
> Remember: we are using a connection string to keep this sample simple; however, parcel will embed the connection string into your published bundle which is not suitable for production as it may leak secrets. For production client side applications, you may be interested in the [@azure/identity][identity] package which provides a set of credential implementations for both NodeJS and the browser.
41+
> Remember: we are using a connection string to keep this sample simple; however, parcel will embed the connection string into your published bundle which is not suitable for production as it may leak secrets. For production client side applications, you may be interested in the [@azure/identity][identity] package which provides a set of credential implementations for both NodeJS and the browser. Alternatively, you may generate a SAS URL from your server-side component and provide it to your client at runtime.
4242
4343
Install the various packages as well as the TypeScript compiler using:
4444

samples/web-workers/arm-template.json

+3-5
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,7 @@
5656
"type": "blobServices",
5757
"apiVersion": "2019-06-01",
5858
"name": "default",
59-
"dependsOn": [
60-
"[variables('storageAccountName')]"
61-
],
59+
"dependsOn": ["[variables('storageAccountName')]"],
6260
"properties": {
6361
"cors": {
6462
"corsRules": [
@@ -88,9 +86,9 @@
8886
}
8987
],
9088
"outputs": {
91-
"azure_storage_blob_connection_string": {
89+
"azure_storage_blob_sas_url": {
9290
"type": "string",
93-
"value": "[concat('BlobEndpoint=https://',variables('storageAccountName'),'.blob.core.windows.net/','blobs',';SharedAccessSignature=', listAccountSas(variables('storageAccountName'), '2019-06-01', variables('accountSasProperties')).accountSasToken)]"
91+
"value": "[concat('https://',variables('storageAccountName'),'.blob.core.windows.net/','blobs','?', listAccountSas(variables('storageAccountName'), '2019-06-01', variables('accountSasProperties')).accountSasToken)]"
9492
},
9593
"azure_storage_blob_container_name": {
9694
"type": "string",

samples/web-workers/js/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,6 @@
1818
],
1919
"dependencies": {
2020
"@azure/storage-blob": "^12.5.0",
21-
"jsdom": "^16.5.0"
21+
"jsdom": "^19.0.0"
2222
}
2323
}

samples/web-workers/js/sample.env

-6
This file was deleted.

samples/web-workers/js/worker.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@ import { ContainerClient } from "@azure/storage-blob";
88
async function uploadToStorageBlob() {
99
// For example, in Azure public cloud, a container SAS URL has the form of
1010
// `https://${account}.blob.core.windows.net/${containerName}?${sasToken}`
11-
const containerSasUrl = "<container SAS url>";
11+
const containerSasUrl = ""; // <replace this empty string with your SAS URL>
12+
13+
if (!containerSasUrl) {
14+
throw new Error("Please replace the placeholder value of containerSasUrl with your SAS URL.");
15+
}
1216

1317
const data = "Hello, Web Workers!";
1418

samples/web-workers/ts/sample.env

-6
This file was deleted.

samples/web-workers/ts/worker.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@ import { ContainerClient } from "@azure/storage-blob";
99
async function uploadToStorageBlob() {
1010
// For example, in Azure public cloud, a container SAS URL has the form of
1111
// `https://${account}.blob.core.windows.net/${containerName}?${sasToken}`
12-
const containerSasUrl = "<container SAS url>";
12+
const containerSasUrl = ""; // <replace this empty string with your SAS URL>
13+
14+
if (!containerSasUrl) {
15+
throw new Error("Please replace the placeholder value of containerSasUrl with your SAS URL.");
16+
}
1317

1418
const data = "Hello, Web Workers!";
1519

0 commit comments

Comments
 (0)