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
?
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.
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.
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.
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.
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.
In the end I solved it using this, inside a defpage, with noir.request
required as request
:
((:headers (request/ring-request)) "host")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With