-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add SSR implementation w/ help of bulmex
- Loading branch information
Showing
27 changed files
with
421 additions
and
306 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,61 +1,70 @@ | ||
{-# LANGUAGE LambdaCase #-} | ||
{-# LANGUAGE OverloadedStrings #-} | ||
{-# LANGUAGE RecordWildCards #-} | ||
|
||
module Main where | ||
|
||
import Common.Xsrf | ||
import qualified Data.Text.Encoding as Text | ||
import Awe.Back.DB.Cli | ||
import Awe.Back.Web | ||
import Data.Time | ||
import Database.PostgreSQL.Simple (connectPostgreSQL) | ||
import DB.Cli | ||
import Lib | ||
import Network.URI | ||
import Options.Applicative | ||
import Reflex.Bulmex.Html | ||
import Servant.Auth.Server | ||
|
||
newtype BackendSettings = BackendSettings { | ||
serveFolder :: FilePath | ||
} | ||
newtype BackendSettings = BackendSettings | ||
{ serveFolder :: FilePath | ||
} | ||
|
||
defaultStaticFolder :: FilePath | ||
defaultStaticFolder | ||
= "dist-ghcjs/build/x86_64-linux/ghcjs-8.4.0.1/frontend-1.0.0.0/x/webservice/build/webservice/webservice.jsexe" | ||
defaultStaticFolder = | ||
"dist-ghcjs/build/x86_64-linux/ghcjs-8.4.0.1/frontend-1.0.0.0/x/webservice/build/webservice/webservice.jsexe" | ||
|
||
main :: IO () | ||
main = do | ||
(connString, BackendSettings{..}) <- readSettings | ||
(connString, BackendSettings {..}) <- readSettings | ||
conn <- connectPostgreSQL $ unConnectionString connString | ||
jwtKey <- generateKey | ||
let settings = ApiSettings | ||
{ cookieSettings = cookieConf | ||
, jwtSettings = defaultJWTSettings jwtKey | ||
, connection = conn | ||
} | ||
let settings = | ||
ApiSettings | ||
{ cookieSettings = cookieConf | ||
, jwtSettings = defaultJWTSettings jwtKey | ||
, connection = conn | ||
, headSettings = | ||
HeadSettings | ||
{ _head_js = | ||
[defScript{ | ||
_script_uri = maybe | ||
(error "could not parse uri all.js") id | ||
$ (parseURIReference "all.js") | ||
}] | ||
, _head_css = [] | ||
, _head_title = "awesomeproj" | ||
} | ||
} | ||
webAppEntry settings serveFolder | ||
where | ||
where | ||
cookieConf = | ||
defaultCookieSettings | ||
{ cookieIsSecure = NotSecure -- allow setting of cookies over http, the reason for this is that we should stop providing http support, *or*, give all features on http. | ||
, cookieMaxAge = Just $ secondsToDiffTime $ 60 * 60 * 24 * 365 | ||
, cookieXsrfSetting = Just $ | ||
def { xsrfCookieName = Text.encodeUtf8 cookieName | ||
, xsrfHeaderName = Text.encodeUtf8 headerName | ||
} | ||
|
||
, cookieXsrfSetting = Nothing | ||
} | ||
|
||
readSettings :: IO (PgConnectionString, BackendSettings) | ||
readSettings = customExecParser (prefs showHelpOnError) $ info | ||
( helper | ||
<*> ((,) <$> postgresOptions <*> backendOptions) | ||
) | ||
( fullDesc <> Options.Applicative.header "Migrations" <> progDesc | ||
"Running the webservice" | ||
) | ||
readSettings = | ||
customExecParser (prefs showHelpOnError) $ | ||
info | ||
(helper <*> ((,) <$> postgresOptions <*> backendOptions)) | ||
(fullDesc <> Options.Applicative.header "Migrations" <> | ||
progDesc "Running the webservice") | ||
|
||
backendOptions :: Parser BackendSettings | ||
backendOptions = BackendSettings <$> strOption | ||
( short 's' | ||
<> long "static-folder" | ||
<> metavar "STATIC_FOLDER_DIR" | ||
<> value defaultStaticFolder | ||
<> help "The Postgres database connection string" | ||
<> showDefault | ||
) | ||
backendOptions = | ||
BackendSettings <$> | ||
strOption | ||
(short 's' <> long "static-folder" <> metavar "STATIC_FOLDER_DIR" <> | ||
value defaultStaticFolder <> | ||
help "The Postgres database connection string" <> | ||
showDefault) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
{-# LANGUAGE DataKinds #-} | ||
{-# LANGUAGE TypeOperators #-} | ||
|
||
{-# OPTIONS_GHC -Wno-missing-monadfail-instances #-} | ||
{-# OPTIONS_GHC -fno-warn-orphans #-} | ||
|
||
|
||
module Awe.Back.Render | ||
( renderHtmlEndpoint | ||
) where | ||
|
||
import Awe.Common | ||
import Awe.Front.Main | ||
import Control.Monad.IO.Class (liftIO) | ||
import qualified Data.ByteString as BS | ||
import Reflex.Bulmex.Html (HeadSettings, htmlWidget) | ||
import Reflex.Dom.Builder.Static | ||
import Servant | ||
import Servant.Auth.Server | ||
|
||
renderHtmlEndpoint :: HeadSettings -> AuthResult User -> Handler BS.ByteString | ||
renderHtmlEndpoint settings authRes = do | ||
liftIO $ do | ||
putStrLn "authres is" | ||
print authRes | ||
fmap snd $ liftIO $ renderStatic $ | ||
htmlWidget settings $ main $ IniState $ toMaybe authRes | ||
|
||
toMaybe :: AuthResult User -> Maybe User | ||
toMaybe (Authenticated auth) = Just auth | ||
toMaybe _ = Nothing |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.