Move Accept HTML in Yore.Servant
This commit is contained in:
parent
f2a136d27c
commit
0bf734730b
11
app/Main.hs
11
app/Main.hs
@ -19,12 +19,10 @@ import Data.Proxy (Proxy (..))
|
||||
import Data.Text (Text)
|
||||
import Data.Time (Day, LocalTime (..), TimeOfDay (..), ZonedTime (..), addDays, toGregorian)
|
||||
import GHC.Generics (Generic)
|
||||
import Network.HTTP.Media ((//), (/:))
|
||||
import Network.HTTP.Types (Status (..))
|
||||
import Network.Wai (Request (..))
|
||||
import Servant
|
||||
( Accept (..)
|
||||
, Capture
|
||||
( Capture
|
||||
, Get
|
||||
, Handler
|
||||
, MimeRender (..)
|
||||
@ -59,7 +57,7 @@ import Yore.Download (downloadInto)
|
||||
import Yore.Error (Error (..))
|
||||
import Yore.Schedule (schedule)
|
||||
import Yore.Scrape (Issue (..), getIssuesByDay)
|
||||
import Yore.Servant (GetSendfile, Sendfile (..))
|
||||
import Yore.Servant (GetSendfile, HTML, Sendfile (..))
|
||||
import Yore.Time (addYears, getCurrentDay, getSecondsUntilMidnight)
|
||||
|
||||
import qualified Envy
|
||||
@ -232,11 +230,6 @@ instance MimeRender HTML RootModel where
|
||||
|
||||
-- Utils
|
||||
|
||||
data HTML
|
||||
|
||||
instance Accept HTML where
|
||||
contentType _ = "text" // "html" /: ("charset", "utf-8")
|
||||
|
||||
get100YearsAgo :: IO (Either Error Day)
|
||||
get100YearsAgo = runExceptT $ getTodayWithOffset (-100) 0
|
||||
|
||||
|
||||
@ -1,11 +1,13 @@
|
||||
{-# LANGUAGE OverloadedRecordDot #-}
|
||||
{-# LANGUAGE OverloadedStrings #-}
|
||||
{-# LANGUAGE TypeFamilies #-}
|
||||
|
||||
module Yore.Servant (GetSendfile, Sendfile (..)) where
|
||||
module Yore.Servant (GetSendfile, Sendfile (..), HTML) where
|
||||
|
||||
import Network.HTTP.Media ((//), (/:))
|
||||
import Network.HTTP.Types (ResponseHeaders, status200)
|
||||
import Network.Wai (responseFile)
|
||||
import Servant (HasServer (..))
|
||||
import Servant (Accept (..), HasServer (..))
|
||||
import Servant.Server.Internal.Delayed (runAction)
|
||||
import Servant.Server.Internal.RouteResult (RouteResult (..))
|
||||
import Servant.Server.Internal.Router (Router' (..))
|
||||
@ -29,3 +31,8 @@ instance HasServer GetSendfile context where
|
||||
route _ _ action = RawRouter $ \env request respond ->
|
||||
runAction action env request respond $ \sendfile ->
|
||||
Route $ responseFile status200 sendfile.headers sendfile.path Nothing
|
||||
|
||||
data HTML
|
||||
|
||||
instance Accept HTML where
|
||||
contentType _ = "text" // "html" /: ("charset", "utf-8")
|
||||
|
||||
@ -50,6 +50,7 @@ library
|
||||
, directory
|
||||
, filepath
|
||||
, html-parse
|
||||
, http-media
|
||||
, http-types
|
||||
, lens
|
||||
, modern-uri
|
||||
@ -81,7 +82,6 @@ executable yore
|
||||
, bytestring
|
||||
, filepath
|
||||
, opium
|
||||
, http-media
|
||||
, http-types
|
||||
, servant-server
|
||||
, text
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user