Every time I tried to run this code, the compiler returns a 'not in scope' error for the variables redirectUrlGraphEmail, redirectUrlGraphPost, aboutContents, and staticDir:
routes :: [ (String, ServerPart Response)]
routes = [
("graph-fb", seeOther redirectUrlGraphEmail $ toResponse ""),
("post-fb", seeOther redirectUrlGraphPost $ toResponse ""),
("about", aboutResponse aboutContents),
("static", serveDirectory DisableBrowsing [] staticDir)]
These variables are declared by:
staticDir <- getStaticDir
redirectUrlGraphEmail <- retrieveAuthURL testUrl
redirectUrlGraphPost <- retrieveAuthURL testPostUrl
aboutContents <- LazyIO.readFile $ markdownPath ++ "README.md"
privacyContents <- LazyIO.readFile $ markdownPath ++ "PRIVACY.md"
but I am not sure where should I add these lines into the module. Any help here?
I don't know happstack but it seems that your variables
redirectUrlGraphEmailetc. are defined in your main (or in some monad at least), right? And then you want to definerouteas a separate function in your module.The thing is, the variables you define (that you bind with
<-to be precise) in yourmainare local to yourmain, so the rest of your program doesn't have access to them (which is why the compiler tells you they're not in scope when you try to use them inroutes). If you want to make use of them, you need to defineroutesas a function taking them as parameters, so in your case:And then from your
maincallrouteswith the variables you've bind. Am I making sense?