Skip to content

Commit

Permalink
Add cors headers (#469)
Browse files Browse the repository at this point in the history
  • Loading branch information
sigma-andex committed Sep 1, 2022
1 parent b9157da commit 3209916
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion config/routes
Expand Up @@ -15,7 +15,7 @@

/builtins/docs/#Text BuiltinDocsR GET

/search SearchR GET
/search SearchR GET OPTIONS

/help HelpR GET
/help/authors HelpAuthorsR GET
Expand Down
8 changes: 8 additions & 0 deletions src/Handler/Search.hs
@@ -1,6 +1,7 @@

module Handler.Search
( getSearchR
, optionsSearchR
, SearchResult(..)
, interleave
) where
Expand Down Expand Up @@ -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
Expand All @@ -53,6 +60,7 @@ getSearchR = do

urls <- getRelatedUrls query npages hasMore
addLinkHeader urls
addHeader "Access-Control-Allow-Origin" "*"

partial <- lookupGetParam partialParam
if isJust partial
Expand Down

0 comments on commit 3209916

Please sign in to comment.