Skip to content

Commit e0b362b

Browse files
authored
Add web-pubsub to CI, update samples (Azure#15000)
1 parent 68d27b5 commit e0b362b

File tree

25 files changed

+394
-98
lines changed

25 files changed

+394
-98
lines changed

sdk/web-pubsub/ci.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# NOTE: Please refer to https://aka.ms/azsdk/engsys/ci-yaml before editing this file.
2+
3+
trigger:
4+
branches:
5+
include:
6+
- master
7+
- main
8+
- release/*
9+
- hotfix/*
10+
paths:
11+
include:
12+
- sdk/web-pubsub/
13+
14+
pr:
15+
branches:
16+
include:
17+
- master
18+
- main
19+
- feature/*
20+
- release/*
21+
- hotfix/*
22+
paths:
23+
include:
24+
- sdk/web-pubsub/
25+
26+
extends:
27+
template: ../../eng/pipelines/templates/stages/archetype-sdk-client.yml
28+
parameters:
29+
ServiceDirectory: web-pubsub
30+
Artifacts:
31+
- name: azure-web-pubsub
32+
safeName: webpubsub
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
## 1.0.0-beta.1 (2021-04-22)
1+
## 1.0.0-beta.1 (2021-04-23)
22

33
This is the first release of the @azure/web-pubsub-express package.

sdk/web-pubsub/web-pubsub-express/package.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,7 @@
122122
"//sampleConfiguration": {
123123
"productName": "Azure Web PubSub CloudEvents Handlers for Express",
124124
"productSlugs": [
125-
"azure",
126-
"azure-web-pubsub",
127-
"express"
125+
"azure"
128126
]
129127
}
130128
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
---
2+
page_type: sample
3+
languages:
4+
- javascript
5+
products:
6+
- azure
7+
urlFragment: web-pubsub-express-javascript
8+
---
9+
10+
# Azure Web PubSub CloudEvents Handlers for Express client library samples for JavaScript
11+
12+
These sample programs show how to use the JavaScript client libraries for Azure Web PubSub CloudEvents Handlers for Express in some common scenarios.
13+
14+
| **File Name** | **Description** |
15+
| ------------------- | --------------------------------------------------------- |
16+
| [server.js][server] | Demonstrates handling Web PubSub CloudEvents with Express |
17+
18+
## Prerequisites
19+
20+
The sample programs are compatible with Node.js >=12.0.0.
21+
22+
You need [an Azure subscription][freesub] to run these sample programs.
23+
24+
Samples retrieve credentials to access the service endpoint from environment variables. Alternatively, edit the source code to include the appropriate credentials. See each individual sample for details on which environment variables/credentials it requires to function.
25+
26+
Adapting the samples to run in the browser may require some additional consideration. For details, please see the [package README][package].
27+
28+
## Setup
29+
30+
To run the samples using the published version of the package:
31+
32+
1. Install the dependencies using `npm`:
33+
34+
```bash
35+
npm install
36+
```
37+
38+
2. Edit the file `sample.env`, adding the correct credentials to access the Azure service and run the samples. Then rename the file from `sample.env` to just `.env`. The sample programs will read this file automatically.
39+
40+
3. Run whichever samples you like (note that some samples may require additional setup, see the table above):
41+
42+
```bash
43+
node server.js
44+
```
45+
46+
Alternatively, run a single sample with the correct environment variables set (setting up the `.env` file is not required if you do this), for example (cross-platform):
47+
48+
```bash
49+
npx cross-env node server.js
50+
```
51+
52+
[server]: https://github.com/Azure/azure-sdk-for-js/blob/master/sdk/web-pubsub/web-pubsub-express/samples/v1/javascript/server.js
53+
[freesub]: https://azure.microsoft.com/free/
54+
[package]: https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/web-pubsub/web-pubsub-express/README.md
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"name": "azure-web-pubsub-express-samples-js",
3+
"private": true,
4+
"version": "1.0.0",
5+
"description": "Azure Web PubSub CloudEvents Handlers for Express client library samples for JavaScript",
6+
"engine": {
7+
"node": ">=12.0.0"
8+
},
9+
"repository": {
10+
"type": "git",
11+
"url": "git+https://github.com/Azure/azure-sdk-for-js.git",
12+
"directory": "sdk/web-pubsub/web-pubsub-express"
13+
},
14+
"keywords": [
15+
"Azure",
16+
"cloud"
17+
],
18+
"author": "Microsoft Corporation",
19+
"license": "MIT",
20+
"bugs": {
21+
"url": "https://github.com/Azure/azure-sdk-for-js/issues"
22+
},
23+
"homepage": "https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/web-pubsub/web-pubsub-express",
24+
"dependencies": {
25+
"@azure/web-pubsub-express": "next",
26+
"dotenv": "latest"
27+
}
28+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
2+
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// Copyright (c) Microsoft Corporation.
2+
// Licensed under the MIT License.
3+
4+
/**
5+
* @summary Demonstrates handling Web PubSub CloudEvents with Express
6+
*/
7+
8+
const { WebPubSubEventHandler } = require("@azure/web-pubsub-express");
9+
const express = require("express");
10+
11+
const handler = new WebPubSubEventHandler("chat", ["https://xxx.webpubsub.azure.com"], {
12+
dumpRequest: false,
13+
handleConnect(req, res) {
14+
console.log(req);
15+
res.success();
16+
// or fail
17+
// res.fail(401);
18+
},
19+
onConnected(connectedRequest) {
20+
console.log(connectedRequest);
21+
},
22+
handleUserEvent(req, res) {
23+
console.log(req);
24+
res.success("Hello", "text");
25+
}
26+
});
27+
28+
const app = express();
29+
30+
app.use(handler.getMiddleware());
31+
32+
app.listen(3000, () =>
33+
console.log(`Azure WebPubSub Upstream ready at http://localhost:3000${handler.path}`)
34+
);
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
---
2+
page_type: sample
3+
languages:
4+
- typescript
5+
products:
6+
- azure
7+
urlFragment: web-pubsub-express-typescript
8+
---
9+
10+
# Azure Web PubSub CloudEvents Handlers for Express client library samples for TypeScript
11+
12+
These sample programs show how to use the TypeScript client libraries for Azure Web PubSub CloudEvents Handlers for Express in some common scenarios.
13+
14+
| **File Name** | **Description** |
15+
| ------------------- | --------------------------------------------------------- |
16+
| [server.ts][server] | Demonstrates handling Web PubSub CloudEvents with Express |
17+
18+
## Prerequisites
19+
20+
The sample programs are compatible with Node.js >=12.0.0.
21+
22+
Before running the samples in Node, they must be compiled to JavaScript using the TypeScript compiler. For more information on TypeScript, see the [TypeScript documentation][typescript]. Install the TypeScript compiler using:
23+
24+
```bash
25+
npm install -g typescript
26+
```
27+
28+
You need [an Azure subscription][freesub] to run these sample programs.
29+
30+
Samples retrieve credentials to access the service endpoint from environment variables. Alternatively, edit the source code to include the appropriate credentials. See each individual sample for details on which environment variables/credentials it requires to function.
31+
32+
Adapting the samples to run in the browser may require some additional consideration. For details, please see the [package README][package].
33+
34+
## Setup
35+
36+
To run the samples using the published version of the package:
37+
38+
1. Install the dependencies using `npm`:
39+
40+
```bash
41+
npm install
42+
```
43+
44+
2. Compile the samples:
45+
46+
```bash
47+
npm run build
48+
```
49+
50+
3. Edit the file `sample.env`, adding the correct credentials to access the Azure service and run the samples. Then rename the file from `sample.env` to just `.env`. The sample programs will read this file automatically.
51+
52+
4. Run whichever samples you like (note that some samples may require additional setup, see the table above):
53+
54+
```bash
55+
node dist/server.ts
56+
```
57+
58+
Alternatively, run a single sample with the correct environment variables set (setting up the `.env` file is not required if you do this), for example (cross-platform):
59+
60+
```bash
61+
npx cross-env node dist/server.js
62+
```
63+
64+
[server]: https://github.com/Azure/azure-sdk-for-js/blob/master/sdk/web-pubsub/web-pubsub-express/samples/v1/typescript/src/server.ts
65+
[freesub]: https://azure.microsoft.com/free/
66+
[package]: https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/web-pubsub/web-pubsub-express/README.md
67+
[typescript]: https://www.typescriptlang.org/docs/home.html
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
{
2+
"name": "azure-web-pubsub-express-samples-ts",
3+
"private": true,
4+
"version": "1.0.0",
5+
"description": "Azure Web PubSub CloudEvents Handlers for Express client library samples for TypeScript",
6+
"engine": {
7+
"node": ">=12.0.0"
8+
},
9+
"scripts": {
10+
"build": "tsc",
11+
"prebuild": "rimraf dist/"
12+
},
13+
"repository": {
14+
"type": "git",
15+
"url": "git+https://github.com/Azure/azure-sdk-for-js.git",
16+
"directory": "sdk/web-pubsub/web-pubsub-express"
17+
},
18+
"keywords": [
19+
"Azure",
20+
"cloud"
21+
],
22+
"author": "Microsoft Corporation",
23+
"license": "MIT",
24+
"bugs": {
25+
"url": "https://github.com/Azure/azure-sdk-for-js/issues"
26+
},
27+
"homepage": "https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/web-pubsub/web-pubsub-express",
28+
"dependencies": {
29+
"@azure/web-pubsub-express": "next",
30+
"dotenv": "latest"
31+
},
32+
"devDependencies": {
33+
"typescript": "~4.2.0",
34+
"rimraf": "latest"
35+
}
36+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

0 commit comments

Comments
 (0)