pubsubhubbub / node-pubsubhubbub

102 stars 22 forks source link

Module "forces" me to start a server #2

Open PaulKinlan opened 7 years ago

PaulKinlan commented 7 years ago

I've a number of lightweight web apps using Express where I don't need to start two servers (one front end and the other frontend for the hub).

At least from reading the documentation I don't think I can have express start to use the Server started for the hub logic, so I ended up doing the following:

pubSubSubscriber.on("feed", data => console.log("feed", data));
pubSubSubscriber.on("subscribe", data => console.log("subscribe", data));
pubSubSubscriber.on("unsubscribe", data => console.log("unsubscribe", data));
pubSubSubscriber.on("error", data => console.log("error", data));

app.get("/pubsubhubbub", pubSubSubscriber._onGetRequest.bind(pubSubSubscriber));
app.post("/pubsubhubbub", pubSubSubscriber._onPostRequest.bind(pubSubSubscriber));

I'm reaching right in to the private functions which doesn't smell right to me and is very brittle.

I would love to see a cleaner solution to at least exposing the get and post methods so that I can manage them without starting a server just for the pubsub functionality.

mattmoreira commented 6 years ago

@PaulKinlan, You can use the listener method, that returns an express middleware.

Ex.: const pubSubMiddleware = pubSubSubscriber.listener(); app.use('/pubsubhubbub', pubSubMiddleware);