Get the host address programmatically in webnoir
Asked Answered
D

2

5

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?

Dynamite answered 16/10, 2011 at 10:2 Comment(0)
D
3

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

((:headers (request/ring-request)) "host")
Dynamite answered 16/10, 2011 at 11:44 Comment(0)
M
4

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.

Metrics answered 16/10, 2011 at 10:46 Comment(0)
D
3

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

((:headers (request/ring-request)) "host")
Dynamite answered 16/10, 2011 at 11:44 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.