# Get servername string in an interactive application

**URL:** https://discourse.openondemand.org/t/get-servername-string-in-an-interactive-application/3013
**Category:** Get Help
**Tags:** question
**Created:** [October 12, 2023, 6:56pm UTC](https://discourse.openondemand.org/t/get-servername-string-in-an-interactive-application/3013 "2023-10-12T18:56:41Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![fenz](https://sea1.discourse-cdn.com/flex015/user_avatar/discourse.openondemand.org/fenz/32/496_2.png) [@fenz](https://discourse.openondemand.org/u/fenz)
#### Post date: [October 12, 2023, 6:56pm UTC](https://discourse.openondemand.org/t/get-servername-string-in-an-interactive-application/3013/1 "2023-10-12T18:56:42Z")

</div>

Hi,

I need to get the servername (configured in ood\_portal.yml) from an interactive application.  
Is this variable available there? Is the list of available ruby methods/instances/variables relates to OOD documented anywhere? It would be quite useful to know the information I can access at every interactive application “stage” (like session or context instances available in the template scripts).

Thanks in advance for your help!

---

<div class="post-metadata">

### Author: ![travert](https://sea1.discourse-cdn.com/flex015/user_avatar/discourse.openondemand.org/travert/32/3074_2.png) [@travert](https://discourse.openondemand.org/u/travert)
#### Post date: [October 12, 2023, 7:34pm UTC](https://discourse.openondemand.org/t/get-servername-string-in-an-interactive-application/3013/2 "2023-10-12T19:34:14Z")

</div>

The only page I can think of with the type of info you are asking is here:  
[https://osc.github.io/ood-documentation/latest/how-tos/app-development/interactive/template.html?highlight=context](https://osc.github.io/ood-documentation/latest/how-tos/app-development/interactive/template.html?highlight=context)

The `cluster_id` in the `session` will give you the cluster names, but it sounds like you want the name of the web-node? is that right?

---

<div class="post-metadata">

### Author: ![fenz](https://sea1.discourse-cdn.com/flex015/user_avatar/discourse.openondemand.org/fenz/32/496_2.png) [@fenz](https://discourse.openondemand.org/u/fenz)
#### Post date: [October 18, 2023, 4:06pm UTC](https://discourse.openondemand.org/t/get-servername-string-in-an-interactive-application/3013/3 "2023-10-18T16:06:05Z")

</div>

Thanks a lot for the info about the available objects.  
I indeed wanted to access the “servername” info dynamically but for the moment I think I will avoid using it.  
Many thanks for your help!

---

<div class="post-metadata">

### Author: ![jeff.ohrstrom](https://sea1.discourse-cdn.com/flex015/user_avatar/discourse.openondemand.org/jeff.ohrstrom/32/136_2.png) [@jeff.ohrstrom](https://discourse.openondemand.org/u/jeff.ohrstrom)
#### Post date: [October 23, 2023, 4:36pm UTC](https://discourse.openondemand.org/t/get-servername-string-in-an-interactive-application/3013/4 "2023-10-23T16:36:45Z")

</div>

Technically, because it’s ERB, you can access _any_ Ruby library available. So you may be able to just use `Socket.gethostname` directly (should you need it in the future).

---

<div class="post-metadata">

### Author: ![codecat555](https://sea1.discourse-cdn.com/flex015/user_avatar/discourse.openondemand.org/codecat555/32/1321_2.png) [@codecat555](https://discourse.openondemand.org/u/codecat555)
#### Post date: [October 23, 2023, 6:20pm UTC](https://discourse.openondemand.org/t/get-servername-string-in-an-interactive-application/3013/5 "2023-10-23T18:20:58Z")

</div>

Thanks @jeff.ohrstrom. I tried `Socket.gethostname`, but it didn’t work in our environment because the configured hostname is not the same as the external hostname (i.e. `servername`).

Next, I used the YAML module to parse ood\_portal.yml file. Kind of hacky, but it worked in our dev environment. It failed in production because the permissions on that file are more restrictive there.

Finally, I found another solution. I added a hidden field in our form and populated it from form.js, as follows:

> // set the base url (see before.sh.erb and entrypoint.sh)  
> $(‘#mwi\_base\_url’).val(window.location.protocol + ‘//’ + window.location.host)

Then, I reference the value in our template scripts via `context.mwi_base_url`.

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/flex015/uploads/osc/original/2X/b/bae70bd0ed39a3ae769c2108155f4cb3e9da8385.png) [@system](https://discourse.openondemand.org/u/system)
#### Post date: [April 20, 2024, 6:21pm UTC](https://discourse.openondemand.org/t/get-servername-string-in-an-interactive-application/3013/6 "2024-04-20T18:21:26Z")

</div>

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