Beginnings of HTMX frontend interaction, able to request particular PWs by link names and patch the DOM appropriately
This commit is contained in:
@ -2,13 +2,20 @@ module Core.HTTP ( app ) where
|
||||
|
||||
import Core.Types
|
||||
|
||||
import Feature.Handlers as HD
|
||||
import Core.Templates (renderIndex)
|
||||
import Feature.Sharing.HTTP as Sharing
|
||||
|
||||
import Network.Wai.Middleware.RequestLogger (logStdoutDev)
|
||||
import Web.Scotty.Trans
|
||||
|
||||
app :: PurrApp ()
|
||||
app = do
|
||||
-- Middleware definition
|
||||
middleware logStdoutDev
|
||||
|
||||
get "/:id" HD.pwLookup
|
||||
-- Core Routes
|
||||
get "/" $ do
|
||||
html $ renderIndex
|
||||
|
||||
-- Feature Routes
|
||||
Sharing.routes
|
||||
|
@ -1,39 +1,13 @@
|
||||
module Core.Mongo ( mongoSetup, getAllDocs, findByLink ) where
|
||||
module Core.Mongo ( mongoSetup ) where
|
||||
|
||||
import Core.Types
|
||||
|
||||
import Control.Monad.Reader (MonadIO, lift, ask)
|
||||
import Data.Maybe
|
||||
import Data.Text (Text)
|
||||
import Data.Text (Text)
|
||||
import Database.MongoDB
|
||||
import Prelude
|
||||
|
||||
findByLink :: String -> PurrAction (Maybe Document)
|
||||
findByLink link = do
|
||||
col <- confCollection
|
||||
dataConn <- dataAccess
|
||||
dataConn $ findOne (select ["link" =: link] col)
|
||||
|
||||
getAllDocs :: PurrAction [Document]
|
||||
getAllDocs = do
|
||||
col <- confCollection
|
||||
dataConn <- dataAccess
|
||||
dataConn $ find (select [] col)
|
||||
>>= rest
|
||||
|
||||
dataAccess :: MonadIO m => PurrAction (Action m a -> m a)
|
||||
dataAccess = do
|
||||
appConfig <- lift ask
|
||||
return $ access
|
||||
(mongoPipe $ dbconn appConfig)
|
||||
(mongoAccessMode $ dbconn appConfig)
|
||||
(mongoDatabase $ dbconn appConfig)
|
||||
|
||||
confCollection :: PurrAction Text
|
||||
confCollection = do
|
||||
appConfig <- lift ask
|
||||
return $ collection $ res appConfig
|
||||
|
||||
-- Authenticates to Mongo and returns the MongoContext for the dataDB
|
||||
mongoSetup :: DhallConfig -> IO MongoContext
|
||||
mongoSetup conf = do
|
||||
|
@ -3,12 +3,14 @@
|
||||
|
||||
module Core.Templates ( renderIndex ) where
|
||||
|
||||
import Database.MongoDB (Document)
|
||||
import Text.Blaze.Html.Renderer.String (renderHtml)
|
||||
import qualified Data.Text.Lazy as LT
|
||||
|
||||
import Database.MongoDB (Document)
|
||||
import Text.Blaze.Html.Renderer.Text (renderHtml)
|
||||
import Text.Blaze.Html
|
||||
import Text.Hamlet (shamletFile)
|
||||
import Text.Hamlet (shamletFile)
|
||||
|
||||
import Prelude
|
||||
|
||||
renderIndex :: String -> Maybe String -> String
|
||||
renderIndex link password = renderHtml ( $(shamletFile "./views/index.hamlet") )
|
||||
renderIndex :: LT.Text
|
||||
renderIndex = renderHtml ( $(shamletFile "./views/index.hamlet") )
|
||||
|
@ -31,4 +31,3 @@ data DhallConfig = DhallConfig
|
||||
, mongoUsername :: Text
|
||||
, mongoPassword :: Text
|
||||
} deriving (Generic, Show)
|
||||
|
||||
|
Reference in New Issue
Block a user