Shpadoinkle-router-0.3.0.1: A single page application rounter for Shpadoinkle based on Servant.

Safe HaskellNone
LanguageHaskell2010

Shpadoinkle.Router.Server

Description

Since the single page application URIs are specified with Servant, we can automate much of the process of serving the application with server-side rendering. This module provides the basic infrastructure for serving rendered HTML using the same code that would be used to render the same route on the client-side, ensuring a consistent rendering, whether a URI is accessed via a client-side popstate event or via the initial page load.

Synopsis

Documentation

toFile :: Piece -> ByteString -> File Source #

Helper to serve a ByteString as a file from the web application interface.

defaultSPAServerSettings Source #

Arguments

:: FilePath

Directory to try files

-> IO (Html m a)

Get the index.html page

-> StaticSettings 

Serve index.html generated from a Shpadoinkle view using the static backend, otherwise serve out of a directory.

type family HasRoot l :: Constraint where ... Source #

This is needed in order for file serving to work. If there is no Raw root route, there is no route to serve files such as ./all.min.js which is required for obvious reasons

Equations

HasRoot (Raw :<|> _) = () 
HasRoot (_ :<|> Raw) = () 
HasRoot (_ :<|> (Raw :<|> _)) = () 
HasRoot (View m a :<|> _) = () 
HasRoot (_ :<|> View m a) = () 
HasRoot (_ :<|> (View m a :<|> _)) = () 
HasRoot (_ :<|> l') = HasRoot l' 
HasRoot _ = TypeError (Text "Your SPA type lacks a root route. This is important, because without this we have no way to \n serve the static assets. Please add :<|> Raw as the final alternative \n in your SPA type.") 

serveUI Source #

Arguments

:: (ServeRouter layout route m a, HasRoot layout) 
=> FilePath

Where should we look for static assets?

-> (route -> IO (Html m a))

How shall we get the page based on the requested route?

-> (layout :>> route)

What is the relationship between URIs and routes?

-> Server layout 

class ServeRouter layout route m a where Source #

Serve the UI by generating a Servant Server from the SPA URIs

Methods

serveUIUnsafe Source #

Arguments

:: FilePath

Where should we look for static assets?

-> (route -> IO (Html m a))

How shall we get the page based on the requested route?

-> (layout :>> route)

What is the relationship between URIs and routes?

-> Server layout 
Instances
ServeRouter Raw r m a Source # 
Instance details

Defined in Shpadoinkle.Router.Server

Methods

serveUIUnsafe :: FilePath -> (r -> IO (Html m a)) -> (Raw :>> r) -> Server Raw Source #

(ServeRouter x r m a, ServeRouter y r m a) => ServeRouter (x :<|> y) r m a Source # 
Instance details

Defined in Shpadoinkle.Router.Server

Methods

serveUIUnsafe :: FilePath -> (r -> IO (Html m a)) -> ((x :<|> y) :>> r) -> Server (x :<|> y) Source #

ServeRouter (View n b) r m a Source # 
Instance details

Defined in Shpadoinkle.Router.Server

Methods

serveUIUnsafe :: FilePath -> (r -> IO (Html m a)) -> (View n b :>> r) -> Server (View n b) Source #

ServeRouter sub r m a => ServeRouter (QueryParam sym x :> sub) r m a Source # 
Instance details

Defined in Shpadoinkle.Router.Server

Methods

serveUIUnsafe :: FilePath -> (r -> IO (Html m a)) -> ((QueryParam sym x :> sub) :>> r) -> Server (QueryParam sym x :> sub) Source #

ServeRouter sub r m a => ServeRouter (QueryParams sym x :> sub) r m a Source # 
Instance details

Defined in Shpadoinkle.Router.Server

Methods

serveUIUnsafe :: FilePath -> (r -> IO (Html m a)) -> ((QueryParams sym x :> sub) :>> r) -> Server (QueryParams sym x :> sub) Source #

ServeRouter sub r m a => ServeRouter (QueryFlag sym :> sub) r m a Source # 
Instance details

Defined in Shpadoinkle.Router.Server

Methods

serveUIUnsafe :: FilePath -> (r -> IO (Html m a)) -> ((QueryFlag sym :> sub) :>> r) -> Server (QueryFlag sym :> sub) Source #

ServeRouter sub r m a => ServeRouter (Capture sym x :> sub) r m a Source # 
Instance details

Defined in Shpadoinkle.Router.Server

Methods

serveUIUnsafe :: FilePath -> (r -> IO (Html m a)) -> ((Capture sym x :> sub) :>> r) -> Server (Capture sym x :> sub) Source #

ServeRouter sub r m a => ServeRouter (path :> sub) r m a Source # 
Instance details

Defined in Shpadoinkle.Router.Server

Methods

serveUIUnsafe :: FilePath -> (r -> IO (Html m a)) -> ((path :> sub) :>> r) -> Server (path :> sub) Source #