0

My site is built in Haskell/Servant and Wai/Warp. I need to redirect all requests from my domain.com to www.domain.com with the the 301 or 302 status. I know I can do that with the help of Wai/Warp somehow. How exactly?

startApp :: IO ()
startApp = run 1234 app
Jushiti
  • 165
  • 1
  • 10

1 Answers1

1

The package wai-util has a convenience function redirect' to create such a Response, so you should be able to do something like

app :: Application
app req respond = respond =<< redirect' status302 [] uri
  where
    Just uri = parseURI "http://example.com/"
Cactus
  • 27,075
  • 9
  • 69
  • 149
  • You can look at `req` and decide however you want if and where you want to redirect. – Cactus Apr 20 '16 at 06:33
  • since on localhost I don't have "www" in a request, on localhost I can't debug it, can it? I need it because I don't know exactly what's inside a request and how "www" is represented. – Jushiti Apr 20 '16 at 06:40