Search code examples
haskellyesodstatic-files

Put static files on "/" in Yesod


I'm a Yesod beginner, and want to build a web site which mainly constructed with static files.

It's required to put static files on /, and dynamic page on /foo.

So I prepared static files in static directory (e.g., static/index.html, static/img/bar.gif, static/css/baz.css, ...), and wrote config/routes as follows:

/    StaticR Static getStatic
/foo FooR    GET    POST

Ghc claims that

Exception when trying to run compile-time code:
 Overlapping routes: 
("StaticR","FooR")

How can I resolve this?


Solution

  • ms's comment is correct: you should put FooR before StaticR. In addition, you'll need to turn off overlap checking. The easiest way is probably to use parseRoutesFileNoCheck instead of parseRoutesFile (or parseRoutesNoCheck instead of parseRoutes if you're using the quasiquoter).