diff options
| -rw-r--r-- | .gitignore | 5 | ||||
| -rw-r--r-- | cabal.project | 2 | ||||
| -rw-r--r-- | fig-web/fig-web.cabal (renamed from fig-frontend/fig-frontend.cabal) | 16 | ||||
| -rw-r--r-- | fig-web/main/Main.hs (renamed from fig-frontend/main/Main.hs) | 8 | ||||
| -rw-r--r-- | fig-web/src/Fig/Web.hs (renamed from fig-frontend/src/Fig/Frontend.hs) | 16 | ||||
| -rw-r--r-- | fig-web/src/Fig/Web/Auth.hs (renamed from fig-frontend/src/Fig/Frontend/Auth.hs) | 4 | ||||
| -rw-r--r-- | fig-web/src/Fig/Web/DB.hs (renamed from fig-frontend/src/Fig/Frontend/DB.hs) | 4 | ||||
| -rw-r--r-- | fig-web/src/Fig/Web/State.hs (renamed from fig-frontend/src/Fig/Frontend/State.hs) | 2 | ||||
| -rw-r--r-- | fig-web/src/Fig/Web/Utils.hs (renamed from fig-frontend/src/Fig/Frontend/Utils.hs) | 12 | ||||
| -rw-r--r-- | flake.lock | 268 | ||||
| -rw-r--r-- | flake.nix | 63 |
11 files changed, 49 insertions, 351 deletions
@@ -3,6 +3,5 @@ dist-newstyle node_modules fig-monitor-*.toml fig-bridge-*.toml -fig-frontend.toml -fig-frontend-assets -fig-frontend-client/output/*
\ No newline at end of file +fig-web.toml +fig-web-assets
\ No newline at end of file diff --git a/cabal.project b/cabal.project index 3130a7f..6307b0d 100644 --- a/cabal.project +++ b/cabal.project @@ -6,7 +6,7 @@ packages: fig-monitor-irc/ fig-monitor-bullfrog/ fig-bridge-irc-discord/ - fig-frontend/ + fig-web/ fig-bless/ fig-emulator-gb/ optimization: 2 diff --git a/fig-frontend/fig-frontend.cabal b/fig-web/fig-web.cabal index 9fc8f8e..3cf3502 100644 --- a/fig-frontend/fig-frontend.cabal +++ b/fig-web/fig-web.cabal @@ -1,5 +1,5 @@ cabal-version: 3.4 -name: fig-frontend +name: fig-web version: 0.1.0.0 common defaults @@ -54,16 +54,16 @@ library import: deps hs-source-dirs: src exposed-modules: - Fig.Frontend - Fig.Frontend.Utils - Fig.Frontend.Auth - Fig.Frontend.State - Fig.Frontend.DB + Fig.Web + Fig.Web.Utils + Fig.Web.Auth + Fig.Web.State + Fig.Web.DB -executable fig-frontend +executable fig-web import: defaults import: deps - build-depends: fig-frontend, optparse-applicative + build-depends: fig-web, optparse-applicative hs-source-dirs: main main-is: Main.hs diff --git a/fig-frontend/main/Main.hs b/fig-web/main/Main.hs index 7db5efe..890c010 100644 --- a/fig-frontend/main/Main.hs +++ b/fig-web/main/Main.hs @@ -6,8 +6,8 @@ import Fig.Prelude import Options.Applicative -import Fig.Frontend -import Fig.Frontend.Utils +import Fig.Web +import Fig.Web.Utils data Opts = Opts { busHost :: Text @@ -19,14 +19,14 @@ parseOpts :: Parser Opts parseOpts = do busHost <- strOption (long "bus-host" <> metavar "HOST" <> help "Address of message bus" <> value "localhost") busPort <- strOption (long "bus-port" <> metavar "PORT" <> help "Message bus port" <> showDefault <> value "32050") - config <- strOption (long "config" <> metavar "PATH" <> help "Path to config file" <> showDefault <> value "fig-frontend.toml") + config <- strOption (long "config" <> metavar "PATH" <> help "Path to config file" <> showDefault <> value "fig-web.toml") pure Opts{..} main :: IO () main = do opts <- execParser $ info (parseOpts <**> helper) ( fullDesc - <> header "fig-frontend - public-facing web applications" + <> header "fig-web - public-facing web applications" ) cfg <- loadConfig opts.config server cfg (opts.busHost, opts.busPort) diff --git a/fig-frontend/src/Fig/Frontend.hs b/fig-web/src/Fig/Web.hs index 4c32078..60dbbe7 100644 --- a/fig-frontend/src/Fig/Frontend.hs +++ b/fig-web/src/Fig/Web.hs @@ -1,6 +1,6 @@ {-# Language QuasiQuotes #-} -module Fig.Frontend where +module Fig.Web where import Fig.Prelude @@ -18,7 +18,7 @@ import qualified Data.ByteString.Base64 as BS.Base64 import qualified Data.Set as Set import qualified Network.Wai as Wai -import qualified Network.Wai.Middleware.Static as Wai.Static +-- import qualified Network.Wai.Middleware.Static as Wai.Static import qualified Network.Wai.Handler.Warp as Warp import qualified Network.WebSockets as WS @@ -26,10 +26,10 @@ import qualified Web.Scotty as Sc import Fig.Utils.SExpr import Fig.Bus.Client -import Fig.Frontend.Utils -import Fig.Frontend.Auth -import Fig.Frontend.State -import qualified Fig.Frontend.DB as DB +import Fig.Web.Utils +import Fig.Web.Auth +import Fig.Web.State +import qualified Fig.Web.DB as DB data LiveEvent = LiveEventOnline !(Set.Set Text) @@ -38,7 +38,7 @@ data LiveEvent server :: Config -> (Text, Text) -> IO () server cfg busAddr = do - log $ "Frontend server running on port " <> tshow cfg.port + log $ "Web server running on port " <> tshow cfg.port liveEvents <- Chan.newChan @LiveEvent currentlyLive <- MVar.newMVar Set.empty busClient busAddr @@ -72,7 +72,7 @@ app cfg cmds liveEvents currentlyLive = do log "Connected! Server active." st <- stateRef Sc.scottyApp do - Sc.middleware $ Wai.Static.staticPolicy $ Wai.Static.addBase cfg.assetPath + -- Sc.middleware $ Wai.Static.staticPolicy $ Wai.Static.addBase cfg.assetPath Sc.get "/" $ Sc.redirect "/index.html" Sc.get "/api/check" $ authed cfg \auth -> do Sc.json @[Text] [auth.id, auth.name] diff --git a/fig-frontend/src/Fig/Frontend/Auth.hs b/fig-web/src/Fig/Web/Auth.hs index 63bf804..3076d1f 100644 --- a/fig-frontend/src/Fig/Frontend/Auth.hs +++ b/fig-web/src/Fig/Web/Auth.hs @@ -1,4 +1,4 @@ -module Fig.Frontend.Auth where +module Fig.Web.Auth where import Fig.Prelude @@ -17,7 +17,7 @@ import qualified Jose.Jwt as Jwt import qualified Web.Scotty as Sc import qualified Web.Scotty.Cookie as Sc.C -import Fig.Frontend.Utils +import Fig.Web.Utils data TokenContents = TokenContents { aud :: !Text diff --git a/fig-frontend/src/Fig/Frontend/DB.hs b/fig-web/src/Fig/Web/DB.hs index 51da59e..f166bdf 100644 --- a/fig-frontend/src/Fig/Frontend/DB.hs +++ b/fig-web/src/Fig/Web/DB.hs @@ -1,11 +1,11 @@ -module Fig.Frontend.DB where +module Fig.Web.DB where import Control.Error.Util (hush) import qualified Database.Redis as Redis import Fig.Prelude -import Fig.Frontend.Utils +import Fig.Web.Utils connect :: MonadIO m => Config -> m Redis.Connection connect cfg = liftIO $ Redis.checkedConnect Redis.defaultConnectInfo diff --git a/fig-frontend/src/Fig/Frontend/State.hs b/fig-web/src/Fig/Web/State.hs index 6053105..11e0ece 100644 --- a/fig-frontend/src/Fig/Frontend/State.hs +++ b/fig-web/src/Fig/Web/State.hs @@ -1,6 +1,6 @@ {-# Language TemplateHaskell #-} -module Fig.Frontend.State where +module Fig.Web.State where import Control.Lens.TH (makeLensesFor) import Control.Lens ((<>=)) diff --git a/fig-frontend/src/Fig/Frontend/Utils.hs b/fig-web/src/Fig/Web/Utils.hs index 090c6ba..b6c385a 100644 --- a/fig-frontend/src/Fig/Frontend/Utils.hs +++ b/fig-web/src/Fig/Web/Utils.hs @@ -1,8 +1,8 @@ {-# Language RecordWildCards #-} {-# Language ApplicativeDo #-} -module Fig.Frontend.Utils - ( FigFrontendException(..) +module Fig.Web.Utils + ( FigWebException(..) , loadConfig , Config(..) , websocket @@ -19,13 +19,12 @@ import qualified Web.Scotty as Sc import qualified Toml -newtype FigFrontendException = FigFrontendException Text +newtype FigWebException = FigWebException Text deriving (Show, Eq, Ord) -instance Exception FigFrontendException +instance Exception FigWebException data Config = Config { port :: !Int - , assetPath :: !FilePath , clientId :: !Text , authToken :: !Text , dbHost :: !Text @@ -34,7 +33,6 @@ data Config = Config configCodec :: Toml.TomlCodec Config configCodec = do port <- Toml.int "port" Toml..= (\a -> a.port) - assetPath <- Toml.string "asset_path" Toml..= (\a -> a.assetPath) clientId <- Toml.text "client_id" Toml..= (\a -> a.clientId) authToken <- Toml.text "auth_token" Toml..= (\a -> a.authToken) dbHost <- Toml.text "db_host" Toml..= (\a -> a.dbHost) @@ -42,7 +40,7 @@ configCodec = do loadConfig :: FilePath -> IO Config loadConfig path = Toml.decodeFileEither configCodec path >>= \case - Left err -> throwM . FigFrontendException $ tshow err + Left err -> throwM . FigWebException $ tshow err Right config -> pure config websocket :: ByteString -> (WS.Connection -> IO ()) -> Sc.ScottyM () @@ -1,135 +1,5 @@ { "nodes": { - "docs-search": { - "flake": false, - "locked": { - "lastModified": 1675992564, - "narHash": "sha256-Tk9VSogFHXtXe9O9vuCEfM/PV/S7plMIO0I++fCZn7U=", - "owner": "purs-nix", - "repo": "purescript-docs-search", - "rev": "35822b1d6ce65b1a07f80dd9e2caf15c3ee83e2c", - "type": "github" - }, - "original": { - "owner": "purs-nix", - "repo": "purescript-docs-search", - "type": "github" - } - }, - "flake-utils": { - "locked": { - "lastModified": 1644229661, - "narHash": "sha256-1YdnJAsNy69bpcjuoKdOYQX0YxZBiCYZo4Twxerqv7k=", - "owner": "numtide", - "repo": "flake-utils", - "rev": "3cecb5b042f7f209c56ffd8371b2711a290ec797", - "type": "github" - }, - "original": { - "owner": "numtide", - "repo": "flake-utils", - "type": "github" - } - }, - "flake-utils_2": { - "locked": { - "lastModified": 1618217525, - "narHash": "sha256-WGrhVczjXTiswQaoxQ+0PTfbLNeOQM6M36zvLn78AYg=", - "owner": "numtide", - "repo": "flake-utils", - "rev": "c6169a2772643c4a93a0b5ac1c61e296cba68544", - "type": "github" - }, - "original": { - "owner": "numtide", - "repo": "flake-utils", - "type": "github" - } - }, - "flake-utils_3": { - "locked": { - "lastModified": 1618217525, - "narHash": "sha256-WGrhVczjXTiswQaoxQ+0PTfbLNeOQM6M36zvLn78AYg=", - "owner": "numtide", - "repo": "flake-utils", - "rev": "c6169a2772643c4a93a0b5ac1c61e296cba68544", - "type": "github" - }, - "original": { - "owner": "numtide", - "repo": "flake-utils", - "type": "github" - } - }, - "get-flake": { - "locked": { - "lastModified": 1644686428, - "narHash": "sha256-zkhYsURWFrvEZLkIoBeqFBzSu+cA2u5mo6M8vq9LN7M=", - "owner": "ursi", - "repo": "get-flake", - "rev": "703f15558daa56dfae19d1858bb3046afe68831a", - "type": "github" - }, - "original": { - "owner": "ursi", - "repo": "get-flake", - "type": "github" - } - }, - "lint-utils": { - "inputs": { - "flake-utils": "flake-utils", - "nixpkgs": [ - "purs-nix", - "nixpkgs" - ] - }, - "locked": { - "lastModified": 1707777931, - "narHash": "sha256-PsPb5xMBZ9dPDP04o9vqKEUIEG80Z84/74fPuOMs0ZI=", - "owner": "homotopic", - "repo": "lint-utils", - "rev": "5f11e3e51d8f1aa4ed62a89e90f05953931e105a", - "type": "github" - }, - "original": { - "owner": "homotopic", - "repo": "lint-utils", - "type": "github" - } - }, - "make-shell": { - "locked": { - "lastModified": 1634940815, - "narHash": "sha256-P69OmveboXzS+es1vQGS4bt+ckwbeIExqxfGLjGuJqA=", - "owner": "ursi", - "repo": "nix-make-shell", - "rev": "8add91681170924e4d0591b22f294aee3f5516f9", - "type": "github" - }, - "original": { - "owner": "ursi", - "ref": "1", - "repo": "nix-make-shell", - "type": "github" - } - }, - "make-shell_2": { - "locked": { - "lastModified": 1634940815, - "narHash": "sha256-P69OmveboXzS+es1vQGS4bt+ckwbeIExqxfGLjGuJqA=", - "owner": "ursi", - "repo": "nix-make-shell", - "rev": "8add91681170924e4d0591b22f294aee3f5516f9", - "type": "github" - }, - "original": { - "owner": "ursi", - "ref": "1", - "repo": "nix-make-shell", - "type": "github" - } - }, "nixpkgs": { "locked": { "lastModified": 1708815994, @@ -146,145 +16,9 @@ "type": "github" } }, - "nixpkgs_2": { - "locked": { - "lastModified": 1704161960, - "narHash": "sha256-QGua89Pmq+FBAro8NriTuoO/wNaUtugt29/qqA8zeeM=", - "owner": "NixOS", - "repo": "nixpkgs", - "rev": "63143ac2c9186be6d9da6035fa22620018c85932", - "type": "github" - }, - "original": { - "owner": "NixOS", - "ref": "nixpkgs-unstable", - "repo": "nixpkgs", - "type": "github" - } - }, - "nixpkgs_3": { - "locked": { - "lastModified": 1656549732, - "narHash": "sha256-eILutFZGjfk2bEzfim8S/qyYc//0S1KsCeO+OWbtoR0=", - "owner": "NixOS", - "repo": "nixpkgs", - "rev": "d3248619647234b5dc74a6921bcdf6dd8323eb22", - "type": "github" - }, - "original": { - "owner": "NixOS", - "ref": "nixpkgs-unstable", - "repo": "nixpkgs", - "type": "github" - } - }, - "parsec": { - "locked": { - "lastModified": 1635533376, - "narHash": "sha256-/HrG0UPGnI5VdkhrNrpDiM2+nhdL6lD/bqyGtYv0QDE=", - "owner": "nprindle", - "repo": "nix-parsec", - "rev": "1bf25dd9c5de1257a1c67de3c81c96d05e8beb5e", - "type": "github" - }, - "original": { - "owner": "nprindle", - "repo": "nix-parsec", - "type": "github" - } - }, - "ps-tools": { - "inputs": { - "make-shell": "make-shell_2", - "nixpkgs": "nixpkgs_3", - "utils": "utils" - }, - "locked": { - "lastModified": 1704567308, - "narHash": "sha256-WbFPIkKLtyQOPBUjintckKIYnfs7MvIbmfVsLRSAPlc=", - "owner": "purs-nix", - "repo": "purescript-tools", - "rev": "ac626313141cbee78f06eb3c5e90359f695aef9b", - "type": "github" - }, - "original": { - "owner": "purs-nix", - "repo": "purescript-tools", - "type": "github" - } - }, - "purs-nix": { - "inputs": { - "docs-search": "docs-search", - "get-flake": "get-flake", - "lint-utils": "lint-utils", - "make-shell": "make-shell", - "nixpkgs": "nixpkgs_2", - "parsec": "parsec", - "ps-tools": "ps-tools", - "utils": "utils_2" - }, - "locked": { - "lastModified": 1707933489, - "narHash": "sha256-LP05KSBQ02mgBDiVdW53h9ViFBtFQIo4dT3FCebucI0=", - "owner": "purs-nix", - "repo": "purs-nix", - "rev": "72c9a8b7df0e53ff8b24fef00d9ea74d3a5b6522", - "type": "github" - }, - "original": { - "owner": "purs-nix", - "ref": "ps-0.15", - "repo": "purs-nix", - "type": "github" - } - }, "root": { "inputs": { - "nixpkgs": "nixpkgs", - "ps-tools": [ - "purs-nix", - "ps-tools" - ], - "purs-nix": "purs-nix" - } - }, - "utils": { - "inputs": { - "flake-utils": "flake-utils_2" - }, - "locked": { - "lastModified": 1656044990, - "narHash": "sha256-f01BB7CaOyntOab9XnpH9HD63rGcnu2iyL4M2ubs5F8=", - "owner": "ursi", - "repo": "flake-utils", - "rev": "f53b674a2c90f6202a2f4cd491aba121775490b5", - "type": "github" - }, - "original": { - "owner": "ursi", - "ref": "8", - "repo": "flake-utils", - "type": "github" - } - }, - "utils_2": { - "inputs": { - "flake-utils": "flake-utils_3" - }, - "locked": { - "lastModified": 1656044990, - "narHash": "sha256-f01BB7CaOyntOab9XnpH9HD63rGcnu2iyL4M2ubs5F8=", - "owner": "ursi", - "repo": "flake-utils", - "rev": "f53b674a2c90f6202a2f4cd491aba121775490b5", - "type": "github" - }, - "original": { - "owner": "ursi", - "ref": "8", - "repo": "flake-utils", - "type": "github" + "nixpkgs": "nixpkgs" } } }, @@ -3,16 +3,12 @@ inputs = { nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; - ps-tools.follows = "purs-nix/ps-tools"; - purs-nix.url = "github:purs-nix/purs-nix/ps-0.15"; }; outputs = { self, nixpkgs, ... }@inputs: let system = "x86_64-linux"; pkgs = nixpkgs.legacyPackages.${system}; - ps-tools = inputs.ps-tools.legacyPackages.${system}; - purs-nix = inputs.purs-nix { inherit system; }; haskellOverrides = self: super: { scotty = self.callHackageDirect { @@ -32,32 +28,12 @@ fig-bridge-irc-discord = self.callCabal2nix "fig-bridge-irc-discord" ./fig-bridge-irc-discord {}; fig-bless = self.callCabal2nix "fig-bless" ./fig-bless {}; fig-emulator-gb = self.callCabal2nix "fig-emulator-gb" ./fig-emulator-gb {}; - fig-frontend = self.callCabal2nix "fig-frontend" ./fig-frontend {}; + fig-web = self.callCabal2nix "fig-web" ./fig-web {}; }; haskellPackages = pkgs.haskell.packages.ghc94.override { overrides = haskellOverrides; }; - purescript = purs-nix.purs { - dependencies = [ - "console" - "effect" - "prelude" - "random" - "refs" - "web-html" - "web-dom" - "web-uievents" - "canvas" - "argonaut" - "fetch" - "fetch-argonaut" - ]; - dir = ./fig-frontend-client; - srcs = [ "src" ]; - }; - fig-frontend-client = purescript.bundle {}; - figBusModule = { config, lib, ... }: let cfg = config.colonq.services.fig-bus; @@ -77,7 +53,6 @@ }; config = lib.mkIf cfg.enable { systemd.services."colonq.fig-bus" = { - after = ["network-online.target"]; wantedBy = ["network-online.target"]; serviceConfig = { Restart = "on-failure"; @@ -277,12 +252,12 @@ }; }; }; - figFrontendModule = { config, lib, ... }: + figWebModule = { config, lib, ... }: let - cfg = config.colonq.services.fig-frontend; + cfg = config.colonq.services.fig-web; in { - options.colonq.services.fig-frontend = { - enable = lib.mkEnableOption "Enable the fig web frontend"; + options.colonq.services.fig-web = { + enable = lib.mkEnableOption "Enable the fig web server"; busHost = lib.mkOption { type = lib.types.str; default = "127.0.0.1"; @@ -296,9 +271,9 @@ configFile = lib.mkOption { type = lib.types.path; description = "Path to config file"; - default = pkgs.writeText "fig-frontend.toml" '' + default = pkgs.writeText "fig-web.toml" '' port = 8000 - asset_path = "./fig-frontend-assets" + asset_path = "./fig-web-assets" client_id = "" auth_token = "" db_host = "" @@ -306,17 +281,17 @@ }; }; config = lib.mkIf cfg.enable { - systemd.services."colonq.fig-frontend" = { + systemd.services."colonq.fig-web" = { wantedBy = ["multi-user.target"]; serviceConfig = { Restart = "on-failure"; - ExecStart = "${haskellPackages.fig-frontend}/bin/fig-frontend --bus-host ${cfg.busHost} --bus-port ${toString cfg.busPort} --config ${cfg.configFile}"; + ExecStart = "${haskellPackages.fig-web}/bin/fig-web --bus-host ${cfg.busHost} --bus-port ${toString cfg.busPort} --config ${cfg.configFile}"; DynamicUser = "yes"; - RuntimeDirectory = "colonq.fig-frontend"; + RuntimeDirectory = "colonq.fig-web"; RuntimeDirectoryMode = "0755"; - StateDirectory = "colonq.fig-frontend"; + StateDirectory = "colonq.fig-web"; StateDirectoryMode = "0700"; - CacheDirectory = "colonq.fig-frontend"; + CacheDirectory = "colonq.fig-web"; CacheDirectoryMode = "0750"; }; }; @@ -333,7 +308,7 @@ fig-monitor-bullfrog fig-bridge-irc-discord fig-bless - fig-frontend + fig-web fig-emulator-gb ]; withHoogle = true; @@ -341,13 +316,6 @@ haskellPackages.cabal-install haskellPackages.haskell-language-server pkgs.nodejs - (purescript.command {}) - ps-tools.for-0_15.purescript-language-server - purs-nix.esbuild - purs-nix.purescript - pkgs.m4 - pkgs.dhall - pkgs.dhall-json ]; }; packages.x86_64-linux = { @@ -360,9 +328,8 @@ figMonitorBullfrog = haskellPackages.fig-monitor-bullfrog; figBridgeIRCDiscord = haskellPackages.fig-bridge-irc-discord; figBless = haskellPackages.fig-bless; - # figBlessStatic = haskellPackagesStatic.fig-bless; figEmulatorGB = haskellPackages.fig-emulator-gb; - figFrontend = haskellPackages.fig-frontend; + figWeb = haskellPackages.fig-web; }; apps.x86_64-linux.default = { type = "app"; @@ -374,7 +341,7 @@ figMonitorDiscord = figMonitorDiscordModule; figMonitorIRC = figMonitorIRCModule; figBridgeIRCDiscord = figBridgeIRCDiscordModule; - figFrontend = figFrontendModule; + figWeb = figWebModule; }; }; } |
