Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get the host address programmatically in webnoir

Tags:

clojure

noir

I'm developing a Clojure webnoir app and I need to construct a callback url (for Twitter oauth) that is different in dev-mode than it is in production mode. In dev-mode it needs to be localhost:8080/smth and on production (heroku) obviously something else like http://smooth-lightning-xxxx.herokuapp.com/smth. How do I get the localhost:8080 part programmatically in a defpage?

like image 653
Michiel Borkent Avatar asked Oct 16 '11 10:10

Michiel Borkent


People also ask

How do I find my host IP address?

First, click on your Start Menu and type cmd in the search box and press enter. A black and white window will open where you will type ipconfig /all and press enter. There is a space between the command ipconfig and the switch of /all. Your ip address will be the IPv4 address.

Can we get IP address from hostname?

In an open command line, type ping followed by the hostname (for example, ping dotcom-monitor.com). and press Enter. The command line will show the IP address of the requested web resource in the response.

How can I get local IP address in C#?

By passing the hostname to GetHostByName() method we will get the IP Address. This method returns a structure of type hostent for the specified host name. AddressList[0] gives the ip address and ToString() method is used to convert it to string.

How do I find the IP address and names of all devices on my local network Android?

To check IP address of the local network on the Android device: Go to Settings → Network & internet on the tablet and select Wi-Fi. Tap the name of active network and expand the Advanced section. Find the Network details field with the local IP address.


2 Answers

I haven't tried it, but I think this should work

(ns your-namespace
  (:require noir.request))

and then in defpage:

(let [server-name (:server-name (noir.request/ring-request))]
    ...)

You can also looke at noir middleware if you need to tweak requests and responses a lot.

like image 52
Slartibartfast Avatar answered Oct 04 '22 13:10

Slartibartfast


In the end I solved it using this, inside a defpage, with noir.request required as request:

((:headers (request/ring-request)) "host")
like image 35
Michiel Borkent Avatar answered Oct 04 '22 12:10

Michiel Borkent