-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #76 from anton-k/safe-url
Safe url
- Loading branch information
Showing
25 changed files
with
1,135 additions
and
9 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions
3
examples/mig-example-apps/HtmlTemplate/resources/milligram.min.css
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
module Api ( | ||
Routes (..), | ||
Urls (..), | ||
GreetingRoute, | ||
BlogPostRoute, | ||
QuoteRoute, | ||
WriteFormRoute, | ||
WriteSubmitRoute, | ||
ListPostsRoute, | ||
urls, | ||
server, | ||
) where | ||
|
||
import Mig.Html.IO | ||
import Types | ||
|
||
-- routes | ||
|
||
type GreetingRoute = Get Html | ||
type BlogPostRoute = Optional "id" BlogPostId -> Get Html | ||
type QuoteRoute = Get Html | ||
type WriteFormRoute = Get Html | ||
type WriteSubmitRoute = Body FormUrlEncoded SubmitBlogPost -> Post Html | ||
type ListPostsRoute = Get Html | ||
|
||
data Routes = Routes | ||
{ greeting :: GreetingRoute | ||
, blogPost :: BlogPostRoute | ||
, quote :: QuoteRoute | ||
, listPosts :: ListPostsRoute | ||
, writeForm :: WriteFormRoute | ||
, writeSubmit :: WriteSubmitRoute | ||
} | ||
|
||
-- URLs | ||
|
||
data Urls = Urls | ||
{ greeting :: UrlOf GreetingRoute | ||
, blogPost :: UrlOf BlogPostRoute | ||
, quote :: UrlOf QuoteRoute | ||
, listPosts :: UrlOf ListPostsRoute | ||
, writeForm :: UrlOf WriteFormRoute | ||
, writeSubmit :: UrlOf WriteSubmitRoute | ||
} | ||
|
||
{-| Site URL's | ||
URL's should be listed in the same order as they appear in the server | ||
-} | ||
urls :: Urls | ||
urls = Urls{..} | ||
where | ||
greeting | ||
:| blogPost | ||
:| quote | ||
:| listPosts | ||
:| writeForm | ||
:| writeSubmit = | ||
toUrl (server undefined) | ||
|
||
-- server definition | ||
|
||
-- | Server definition. Note how we assemble it from parts with monoid method mconcat. | ||
server :: Routes -> Server IO | ||
server routes = | ||
addIndex $ | ||
mconcat | ||
[ defaultPage | ||
, "blog" | ||
/. [ readServer | ||
, writeServer | ||
] | ||
] | ||
where | ||
addIndex = addPathLink "index.html" "/" | ||
|
||
-- default main page | ||
defaultPage = | ||
"/" /. routes.greeting | ||
|
||
-- server to read info. | ||
-- We can read blog posts and quotes. | ||
readServer = | ||
toServer | ||
[ "read" | ||
/. mconcat | ||
[ "post" /. routes.blogPost | ||
, "quote" /. routes.quote | ||
] | ||
, "list" /. routes.listPosts | ||
] | ||
|
||
-- server to write new blog posts | ||
writeServer = | ||
"write" | ||
/. [ toServer routes.writeForm | ||
, toServer routes.writeSubmit | ||
] |
Oops, something went wrong.