diff --git a/config/routes b/config/routes index 91ced88..d91b171 100644 --- a/config/routes +++ b/config/routes @@ -15,7 +15,7 @@ /builtins/docs/#Text BuiltinDocsR GET -/search SearchR GET +/search SearchR GET OPTIONS /help HelpR GET /help/authors HelpAuthorsR GET diff --git a/src/Handler/Search.hs b/src/Handler/Search.hs index a4607f8..76ba7a4 100644 --- a/src/Handler/Search.hs +++ b/src/Handler/Search.hs @@ -1,6 +1,7 @@ module Handler.Search ( getSearchR + , optionsSearchR , SearchResult(..) , interleave ) where @@ -38,6 +39,12 @@ pagesParam = "pages" partialParam :: Text partialParam = "partial" +optionsSearchR :: Handler RepPlain +optionsSearchR = do + addHeader "Access-Control-Allow-Origin" "*" + addHeader "Access-Control-Allow-Methods" "GET, OPTIONS" + return $ RepPlain $ toContent ("" :: Text) + getSearchR :: Handler TypedContent getSearchR = do query <- getQuery @@ -53,6 +60,7 @@ getSearchR = do urls <- getRelatedUrls query npages hasMore addLinkHeader urls + addHeader "Access-Control-Allow-Origin" "*" partial <- lookupGetParam partialParam if isJust partial