Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Module "forces" me to start a server #2

Open
PaulKinlan opened this issue Jul 18, 2017 · 1 comment
Open

Module "forces" me to start a server #2

PaulKinlan opened this issue Jul 18, 2017 · 1 comment

Comments

@PaulKinlan
Copy link

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
Copy link

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

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants