# Clearing up a httpNode.post

**URL:** <https://discourse.nodered.org/t/clearing-up-a-httpnode-post/15463>\
**Category:** Developing Nodes\
**Created:** [12 September 2019 13:21 UTC](https://discourse.nodered.org/t/clearing-up-a-httpnode-post/15463 "2019-09-12T13:21:49Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![brettyj](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/brettyj/32/12049_2.png) [@brettyj](https://discourse.nodered.org/u/brettyj)\
**Post date:** [12 September 2019 13:21 UTC](https://discourse.nodered.org/t/clearing-up-a-httpnode-post/15463/1 "2019-09-12T13:21:49Z")

</div>

Hey,

I'm working on a node, which is listening on an endpoint which is set up using a RED.httpNode.post call. I'm having an issue where after deploy the node stops outputting messages, but I am getting a response on the http call.

I also find that removing the node and deploying will still get responses from the node via HTTP (where the HTTP-In node will stop responding if it's deleted and deployed).

My suspcion is that it's the HTTP Post from first load is being kept open, and we need to close this HTTP Post listener on deploy before re-opening it again.

This code on HTTP In seems to clean itself up, but when I run it on my node, \_router.routes is empty

```auto
this.on("close",function() {
                var node = this;
                RED.httpNode._router.stack.forEach(function(route,i,routes) {
                    if (route.route && route.route.path === node.url && route.route.methods[node.method]) {
                        routes.splice(i,1);
                    }
                });
            });

```

What am I doing wrong? There's seems to be no documentation on how to use RED.httpAdmin.post

This is my code:

```auto
        var obj = RED.httpAdmin.post(('/webhook/' + node.id), function(req, res){ WebhookCallback(req, res); } );

        this.on('close', function() {
            console.log("close");
            // tidy up any state
            obj = undefined;
            var node = this;
                RED.httpNode._router.stack.forEach(function(route,i,routes) {

                        routes.splice(i,1);
  
                });
        });

```

I've tried in this example just removing everything for debugging, but it still persists

---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [12 September 2019 13:28 UTC](https://discourse.nodered.org/t/clearing-up-a-httpnode-post/15463/2 "2019-09-12T13:28:58Z")

</div>

The `RED.httpAdmin.post` object is an Express.js application. They don't provide a built-in way of removing a route - hence the code that delves into the internal `_router` object. Because it delves into the internals of express, it is possible they have changed something and the code we have in the HTTP In node needs updating.

The other approach for you to consider is to not add an HTTP end point for each instance of your node - just add it once at the top level of your file and use the a path parameter for the node id so you can then delegate any request to the appropriate node instance if it exists...

```auto
RED.httpAdmin.post('/webhook/:nodeId', function(req,res) {
   var nodeId = req.params.nodeId;
   var node = RED.nodes.getNode(nodeId);
   if (node) { 
      // call the callback function you have added to the individual node instance.
      node.handleWebhookCallback(req,res);
   } else {
      res.send(404).end();
   }
});

```

---

<div class="post-metadata">

**Author:** ![brettyj](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/brettyj/32/12049_2.png) [@brettyj](https://discourse.nodered.org/u/brettyj)\
**Post date:** [12 September 2019 20:05 UTC](https://discourse.nodered.org/t/clearing-up-a-httpnode-post/15463/3 "2019-09-12T20:05:09Z")

</div>

Aha, that's perfect that's solved the issue! Thanks

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [12 September 2019 20:38 UTC](https://discourse.nodered.org/t/clearing-up-a-httpnode-post/15463/4 "2019-09-12T20:38:50Z")

</div>

> [@knolleary](#):
>
> They don't provide a built-in way of removing a route - hence the code that delves into the internal `_router` object. Because it delves into the internals of express, it is possible they have changed something and the code we have in the HTTP In node needs updating.

You can check out my close processing in uibuilder. That has a utility function that will remove things from the routing table. It was a right pain to get right.
