How to run a pubsubhub portal in static site like gatsby

I want to get notification when a user uploads a video. So I am running a pubsubhub server. And
listening in port 1337 in local machine.

var pubsubhub = require("pubsubhubbub"),
topic = " 
hub = "";

exports.handler = async(event, context) => {
var pubsub = pubsubhub.createServer({
callbackUrl: ""


pubsub.on("subscribe", (data) => {

    console.log("Subscribed "+topic+" to "+hub);

pubsub.on("denied", function(data){

pubsub.on("unsubscribe", (data) => {

    console.log("Unsubscribed "+topic+" from "+hub);

pubsub.on("error", function(error){

pubsub.on("feed", (data) => {

    pubsub.unsubscribe(topic, hub);

pubsub.on("listen", () => {
    console.log("Server listening on port %s", pubsub.port);
    pubsub.subscribe(topic, hub, (err) => {
            console.log("Failed subscribing");

return {
    statusCode: 200,
    body: "SUCCESS hub"

Now to implement this in production , I am running a lambda function ’ `deploy-succeeded.js’ where
I have put this pubsub code. But my question is in which port I have to listen?will it be ‘process.env.PORT’

Are you trying to run a listener over the lambda function with a different port?

I’m missing what you are really trying to do here. Can you give a better view of where the pubsubhub server is going to exist?

Yes. I am trying to listen over PORT: 1337 of any update. And here the pubsub server acting as a websocket.

I have edited the code.Please check it.

Github repo

since Lambda functions run for only 10 seconds, I can’t imagine that workflow doing anything useful even if you could usefully open the port at AWS. You wouldn’t be able to connect to some other port via the netlify function address - we would refuse a connection not on port 80 or 443.

Sounds like you need a real server somewhere if you are opening ports to listen for connections?

1 Like