diff --git a/sdk/web-pubsub/web-pubsub-express/README.md b/sdk/web-pubsub/web-pubsub-express/README.md index 63e63e6cb1b3..b795567e47b2 100644 --- a/sdk/web-pubsub/web-pubsub-express/README.md +++ b/sdk/web-pubsub/web-pubsub-express/README.md @@ -38,12 +38,7 @@ npm install @azure/web-pubsub-express const express = require("express"); const { WebPubSubEventHandler } = require("@azure/web-pubsub-express"); -const handler = new WebPubSubEventHandler("chat", { - handleConnect: (req, res) => { - // auth the connection and set the userId of the connection - res.success(); - } -}); +const handler = new WebPubSubEventHandler("chat"); const app = express(); @@ -114,9 +109,6 @@ const express = require("express"); const { WebPubSubEventHandler } = require("@azure/web-pubsub-express"); const handler = new WebPubSubEventHandler("chat", { - handleConnect: (req, res) => { - res.success(); - }, allowedEndpoints: [ "https://.webpubsub.azure.com", "https://.webpubsub.azure.com" @@ -139,11 +131,7 @@ const express = require("express"); const { WebPubSubEventHandler } = require("@azure/web-pubsub-express"); const handler = new WebPubSubEventHandler("chat", { - path: "customPath1", - handleConnect: (req, res) => { - // auth the connection and set the userId of the connection - res.success(); - } + path: "customPath1" }); const app = express(); @@ -151,6 +139,7 @@ const app = express(); app.use(handler.getMiddleware()); app.listen(3000, () => + // Azure WebPubSub Upstream ready at http://localhost:3000/customPath1 console.log(`Azure WebPubSub Upstream ready at http://localhost:3000${handler.path}`) ); ``` diff --git a/sdk/web-pubsub/web-pubsub-express/samples/v1/javascript/server.js b/sdk/web-pubsub/web-pubsub-express/samples/v1/javascript/server.js index 7c6ffd758e74..effd4ec36896 100644 --- a/sdk/web-pubsub/web-pubsub-express/samples/v1/javascript/server.js +++ b/sdk/web-pubsub/web-pubsub-express/samples/v1/javascript/server.js @@ -9,7 +9,6 @@ const { WebPubSubEventHandler } = require("@azure/web-pubsub-express"); const express = require("express"); const handler = new WebPubSubEventHandler("chat", { - path: "/api/webpubsub", handleConnect(req, res) { console.log(req); res.success(); diff --git a/sdk/web-pubsub/web-pubsub-express/src/cloudEventsDispatcher.ts b/sdk/web-pubsub/web-pubsub-express/src/cloudEventsDispatcher.ts index 1b8cea1f1f79..f96946dc683f 100644 --- a/sdk/web-pubsub/web-pubsub-express/src/cloudEventsDispatcher.ts +++ b/sdk/web-pubsub/web-pubsub-express/src/cloudEventsDispatcher.ts @@ -205,8 +205,7 @@ export class CloudEventsDispatcher { switch (eventType) { case EventType.Connect: if (!this.eventHandler?.handleConnect) { - response.statusCode = 401; - response.end("Connect event handler is not configured."); + response.end(); return true; } break; diff --git a/sdk/web-pubsub/web-pubsub-express/test/connect.spec.ts b/sdk/web-pubsub/web-pubsub-express/test/connect.spec.ts index 97c5f7ddee7d..2fa30040ddad 100644 --- a/sdk/web-pubsub/web-pubsub-express/test/connect.spec.ts +++ b/sdk/web-pubsub/web-pubsub-express/test/connect.spec.ts @@ -65,7 +65,7 @@ describe("Can handle connect event", function() { assert.isTrue(endSpy.notCalled); }); - it("Should response with 401 when option is not specified", async function() { + it("Should response with 200 when option is not specified", async function() { const endSpy = sinon.spy(res, "end"); buildRequest(req, "hub", "conn1"); @@ -73,10 +73,10 @@ describe("Can handle connect event", function() { const result = await dispatcher.handleRequest(req, res); assert.isTrue(result, "should handle"); assert.isTrue(endSpy.calledOnce, "should call once"); - assert.equal(401, res.statusCode, "should be 401"); + assert.equal(200, res.statusCode, "should be 200"); }); - it("Should response with 401 when handler is not specified", async function() { + it("Should response with 200 when handler is not specified", async function() { const endSpy = sinon.spy(res, "end"); buildRequest(req, "hub", "conn1"); @@ -84,7 +84,7 @@ describe("Can handle connect event", function() { const result = await dispatcher.handleRequest(req, res); assert.isTrue(result, "should handle"); assert.isTrue(endSpy.calledOnce, "should call once"); - assert.equal(401, res.statusCode, "should be 401"); + assert.equal(200, res.statusCode, "should be 200"); }); it("Should response with error when handler returns error", async function() {