-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathServer.hs
More file actions
25 lines (20 loc) · 683 Bytes
/
Server.hs
File metadata and controls
25 lines (20 loc) · 683 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
{-# LANGUAGE OverloadedStrings #-}
module Server where
import Web.Scotty
import Data.Monoid (mconcat)
import HtmlConvert (convertDocumentNoDoctype)
import Lucid (renderText, renderToFile)
import Data.Text.Lazy (unpack, pack)
import Network.Wai.Middleware.Cors
import MarkDownParse (documentP, runParser)
main = scotty 3000 $ do
middleware simpleCors
get "/:word" $ do
beam <- param "word"
html $ mconcat ["<h1>Scotty, ", beam, " me up!</h1>"]
post "/parse" $ do
md <- param "md"
let parseResult = runParser documentP md
case parseResult of
Left err -> html $ pack (show err)
Right doc -> html $ renderText (convertDocumentNoDoctype doc)