# How to use a core node inside of a custom node implementation

**URL:** https://discourse.nodered.org/t/how-to-use-a-core-node-inside-of-a-custom-node-implementation/28565
**Category:** General
**Created:** [18 June 2020 18:26 UTC](https://discourse.nodered.org/t/how-to-use-a-core-node-inside-of-a-custom-node-implementation/28565 "2020-06-18T18:26:57Z")
**Posts on this page:** 5
**Page:** 4

<div class="post-metadata">

### Author: ![afelix](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/afelix/32/9743_2.png) [@afelix](https://discourse.nodered.org/u/afelix)
#### Post date: [28 June 2020 11:28 UTC](https://discourse.nodered.org/t/how-to-use-a-core-node-inside-of-a-custom-node-implementation/28565/61 "2020-06-28T11:28:00Z")

</div>

> [@framp](#):
>
> As far as I understand I just have to set the request header to
> 
> ```auto
> Access-Control-Allow-Origin: *
> 
> ```
> 
> which I can do with ajax (Found [this](https://stackoverflow.com/questions/3229823/how-can-i-pass-request-headers-with-jquerys-getjson-method) page which shows hot to set the header)

Sorry to disappoint, that's not how CORS works. It's not a header you set in the request, but a header that the server you're requesting has to set in their response...

---

<div class="post-metadata">

### Author: ![cinhcet](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cinhcet/32/438_2.png) [@cinhcet](https://discourse.nodered.org/u/cinhcet)
#### Post date: [28 June 2020 11:29 UTC](https://discourse.nodered.org/t/how-to-use-a-core-node-inside-of-a-custom-node-implementation/28565/62 "2020-06-28T11:29:04Z")

</div>

I will cite myself

> [@cinhcet](#):
>
> Something like this
> 
> ```auto
> RED.httpAdmin.get("/pilightswitch/devices", RED.auth.needsPermission('pilight-switch.read'), function(req, res) {
> res.json(glbl.devices);
> });
> 
> ```
> 
> combined with
> 
> ```auto
> oneditprepare: function() {
> $.getJSON('pilightswitch/devices', function(data) {
> console.log(data);
> });
> }
> 
> ```
> 
> for more details, look at JGKKs links

You put the top code in the javascript file of your node. This will create an http endpoint in that node. So it has nothing to do with the http node. Look at the various examples we have posted where to put that code.  
Since the editor html is served from the same origin as the runtime, you will not have a CORS issue.

---

<div class="post-metadata">

### Author: ![framp](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/framp/32/24174_2.png) [@framp](https://discourse.nodered.org/u/framp)
#### Post date: [28 June 2020 11:50 UTC](https://discourse.nodered.org/t/how-to-use-a-core-node-inside-of-a-custom-node-implementation/28565/63 "2020-06-28T11:50:45Z")

</div>

@afelix Makes sense. Looks like I will spend some time to read about CORS when i finished my custom-node 😄

@cinhcet I now got you 👍 . There are a lot of new node-red terms I have to get familiar with. Now I understand what you mean with `endpoint solution`. And now I also don't need the config node on the client side any more because the device list is retrieved at the server side.

---

<div class="post-metadata">

### Author: ![framp](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/framp/32/24174_2.png) [@framp](https://discourse.nodered.org/u/framp)
#### Post date: [28 June 2020 12:34 UTC](https://discourse.nodered.org/t/how-to-use-a-core-node-inside-of-a-custom-node-implementation/28565/64 "2020-06-28T12:34:53Z")

</div>

@JGKK & @cinhcet - You made my day. Now the list of devices is presented in a drop down list.

Thank you very much for your help and your pushes to get me in the right direction with my first custom-node. With your help I enjoyed to have a steep ramp up on node-red, js, node, client/server communication, CORS, ... Actually all is used in @JGKK s code but I frankly didn't notice it's a dedicated endpoint which is used in in the client code. i was still on the server side - unfortunately.

There is still the error handling and notification missing but nevertheless I would consider the code now beta 😉

Two final node-red questions:

1. Should every device name used in a switch node as soon as it was created be disabled and no creation of switch with the same device is possible? That way every switch becomes a singleton.
2. Right now it's possible to change the device name at any time. Doesn't it make sense to disable a device name change? This is somehow related to my first question.

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)
#### Post date: [27 August 2020 12:34 UTC](https://discourse.nodered.org/t/how-to-use-a-core-node-inside-of-a-custom-node-implementation/28565/65 "2020-08-27T12:34:55Z")

</div>

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.

[Previous page](https://discourse.nodered.org/t/how-to-use-a-core-node-inside-of-a-custom-node-implementation/28565.md?page=3)
