How to do subdomain routing using Haskell

Using Hakyll, which uses snap, I started working on a routing server. Given the following code from my tutorials, I can see the routing, but I would like to have several different applications on my own subdomains, such as oneapp.mysite.com. Is it possible to use a snap-in or any other Haskell server?

site :: Snap () site = ifTop (writeBS "hello world") <|> route [ ("foo", writeBS "bar") , ("echo/:echoparam", echoHandler) ] <|> dir "static" (serveDirectory ".") 
+4
source share
2 answers

I have not done this before, but this is what I would like to try:

Use the wrapSite function to conditionally use routes for your subdomain, and you can check which subdomain was requested using fmap rqServerName getRequest

http://hackage.haskell.org/packages/archive/snap/0.11.0/doc/html/Snap-Snaplet.html#g:7 http://hackage.haskell.org/packages/archive/snap-core /0.9.2.2/doc/html/Snap-Core.html#ghaps http://hackage.haskell.org/packages/archive/snap-core/0.9.2.2/doc/html/Snap-Core.html# g: 10

+1
source

Thank you for the advice, I did it. I did not use bindings, but used fmap rqServerName getRequest and if-then-else . This is a piece of code.

 skite :: Snap () skite = do req <- fmap rqServerName getRequest routes req where routes req = if (req == "www.site1.ro") then (site1) else pass <|> if (req == "site1.ro") then (site1) else pass <|> if (req == "www.site2.ro") then (writeBS req) else pass <|> if (req == "site2.ro") then (writeBS "Nowhere to be found") else pass <|> ifTop (writeBS req) 

I also created the point with the full code here. For further suggestions, please.

0
source

All Articles