add frontend (boilerplate)
This commit is contained in:
@@ -112,7 +112,7 @@ main = do
|
||||
pure (Commit cid colls)
|
||||
A.execParser (A.info (args <**> A.helper) A.idm) >>= \case
|
||||
Args {cmd = Serve} -> do
|
||||
W.runEnv 8080 $ \req respond -> do
|
||||
W.runEnv 8081 $ \req respond -> do
|
||||
case P.parseOnly routeP (W.rawPathInfo req) of
|
||||
Right (SchemaJson path) -> do
|
||||
let [c] = filter ((== path) . (.path)) (head repo.commits).collections
|
||||
@@ -1,5 +1,5 @@
|
||||
cabal-version: 3.4
|
||||
name: acms
|
||||
name: backend
|
||||
version: 0.1.0.0
|
||||
license: BSD-3-Clause
|
||||
license-file: LICENSE
|
||||
@@ -7,7 +7,7 @@ maintainer: aforemny@posteo.de
|
||||
author: Alexander Foremny
|
||||
build-type: Simple
|
||||
|
||||
executable acms
|
||||
executable backend
|
||||
main-is: Main.hs
|
||||
hs-source-dirs: app
|
||||
default-language: GHC2021
|
||||
@@ -1 +1 @@
|
||||
packages: ./*.cabal autotypes/*.cabal
|
||||
packages: */*.cabal
|
||||
|
||||
28
default.nix
28
default.nix
@@ -2,22 +2,40 @@
|
||||
, sources ? import ./nix/sources.nix
|
||||
}:
|
||||
let
|
||||
haskellPackages = pkgs.haskellPackages.override {
|
||||
haskellPackages = pkgs.haskell.packages.ghc98.override {
|
||||
overrides = self: super: {
|
||||
acms = self.callCabal2nix "acms" ./. { };
|
||||
astore = self.callCabal2nix "astore" sources.json2sql { };
|
||||
autotypes = self.callCabal2nix "autotypes" ./autotypes { };
|
||||
json2sql = self.callCabal2nix "json2sql" sources.json2sql { };
|
||||
backend = self.callCabal2nix "backend" ./backend { };
|
||||
frontend = self.callCabal2nix "frontend" ./frontend { };
|
||||
websockets = pkgs.haskell.lib.doJailbreak super.websockets;
|
||||
};
|
||||
};
|
||||
|
||||
jsHaskellPackages = pkgs.pkgsCross.ghcjs.haskell.packages.ghc98.override {
|
||||
overrides = self: super: {
|
||||
frontend = self.callCabal2nix "frontend" ./frontend { };
|
||||
};
|
||||
};
|
||||
in
|
||||
rec {
|
||||
inherit (haskellPackages) acms;
|
||||
inherit (haskellPackages) backend;
|
||||
inherit (jsHaskellPackages) frontend;
|
||||
shell = haskellPackages.shellFor {
|
||||
packages = _: [ acms haskellPackages.autotypes ];
|
||||
packages = _: [
|
||||
haskellPackages.autotypes
|
||||
haskellPackages.backend
|
||||
haskellPackages.frontend
|
||||
];
|
||||
buildInputs = [
|
||||
haskellPackages.cabal-install
|
||||
haskellPackages.ormolu
|
||||
(pkgs.writeScriptBin "reload" ''
|
||||
set -efu
|
||||
${haskellPackages.ghcid.bin}/bin/ghcid -c \
|
||||
'${haskellPackages.cabal-install}/bin/cabal new-repl' \
|
||||
-T ':run Main.main'
|
||||
'')
|
||||
];
|
||||
withHoogle = true;
|
||||
withHaddock = true;
|
||||
|
||||
30
frontend/LICENSE
Normal file
30
frontend/LICENSE
Normal file
@@ -0,0 +1,30 @@
|
||||
Copyright (c) 2024, Alexander Foremny
|
||||
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
|
||||
* Redistributions in binary form must reproduce the above
|
||||
copyright notice, this list of conditions and the following
|
||||
disclaimer in the documentation and/or other materials provided
|
||||
with the distribution.
|
||||
|
||||
* Neither the name of Alexander Foremny nor the names of other
|
||||
contributors may be used to endorse or promote products derived
|
||||
from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
77
frontend/app/Main.hs
Normal file
77
frontend/app/Main.hs
Normal file
@@ -0,0 +1,77 @@
|
||||
module Main where
|
||||
|
||||
#ifndef ghcjs_HOST_OS
|
||||
import Language.Javascript.JSaddle.Warp as JSaddle
|
||||
#endif
|
||||
|
||||
import Data.ByteString.UTF8 qualified as B
|
||||
import Data.Maybe
|
||||
import Miso
|
||||
import Miso.String
|
||||
|
||||
#ifndef ghcjs_HOST_OS
|
||||
import Network.HTTP.Simple
|
||||
import Data.String
|
||||
#else
|
||||
import JavaScript.Web.XMLHttpRequest
|
||||
#endif
|
||||
|
||||
type Model = Maybe Schema
|
||||
|
||||
type Schema = String
|
||||
|
||||
data Action
|
||||
= FetchSchema
|
||||
| SetSchema Schema
|
||||
deriving (Show, Eq)
|
||||
|
||||
#ifndef ghcjs_HOST_OS
|
||||
runApp :: JSM () -> IO ()
|
||||
runApp f = JSaddle.debugOr 8080 (f >> syncPoint) JSaddle.jsaddleApp
|
||||
#else
|
||||
runApp :: IO () -> IO ()
|
||||
runApp app = app
|
||||
#endif
|
||||
|
||||
main :: IO ()
|
||||
main = runApp $ startApp App {..}
|
||||
where
|
||||
initialAction = FetchSchema
|
||||
model = Nothing
|
||||
update = updateModel
|
||||
view = viewModel
|
||||
events = defaultEvents
|
||||
subs = []
|
||||
mountPoint = Nothing
|
||||
logLevel = Off
|
||||
|
||||
updateModel :: Action -> Model -> Effect Action Model
|
||||
updateModel action m =
|
||||
case action of
|
||||
FetchSchema -> m <# do SetSchema <$> fetchSchema
|
||||
SetSchema schema -> noEff (Just schema)
|
||||
|
||||
fetchSchema :: JSM String
|
||||
fetchSchema = fetch "http://localhost:8081/posts.schema.json"
|
||||
|
||||
#ifndef ghcjs_HOST_OS
|
||||
fetch :: String -> JSM String
|
||||
fetch url = B.toString . getResponseBody <$> httpBS (fromString url)
|
||||
#else
|
||||
fetch :: String -> JSM String
|
||||
fetch url = maybe "" B.toString . contents <$> xhrByteString req
|
||||
where
|
||||
req =
|
||||
Request
|
||||
{ reqMethod = GET,
|
||||
reqURI = pack url,
|
||||
reqLogin = Nothing,
|
||||
reqHeaders = [],
|
||||
reqWithCredentials = False,
|
||||
reqData = NoData
|
||||
}
|
||||
#endif
|
||||
|
||||
viewModel :: Model -> View Action
|
||||
viewModel schema =
|
||||
div_ [] [text (toMisoString (fromMaybe ".." schema))]
|
||||
31
frontend/frontend.cabal
Normal file
31
frontend/frontend.cabal
Normal file
@@ -0,0 +1,31 @@
|
||||
cabal-version: 3.4
|
||||
name: frontend
|
||||
version: 0.1.0.0
|
||||
license: BSD-3-Clause
|
||||
license-file: LICENSE
|
||||
maintainer: aforemny@posteo.de
|
||||
author: Alexander Foremny
|
||||
build-type: Simple
|
||||
extra-doc-files: CHANGELOG.md
|
||||
|
||||
executable frontend
|
||||
main-is: Main.hs
|
||||
hs-source-dirs: app
|
||||
default-language: GHC2021
|
||||
default-extensions: CPP OverloadedStrings RecordWildCards
|
||||
ghc-options: -Wall
|
||||
build-depends:
|
||||
base,
|
||||
bytestring,
|
||||
containers,
|
||||
miso,
|
||||
text,
|
||||
utf8-string
|
||||
|
||||
if !arch(javascript)
|
||||
build-depends: jsaddle-warp
|
||||
|
||||
if arch(javascript)
|
||||
build-depends: ghcjs-base
|
||||
else
|
||||
build-depends: http-conduit
|
||||
@@ -11,10 +11,10 @@
|
||||
"homepage": null,
|
||||
"owner": "NixOS",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "6c43a3495a11e261e5f41e5d7eda2d71dae1b2fe",
|
||||
"sha256": "16f329z831bq7l3wn1dfvbkh95l2gcggdwn6rk3cisdmv2aa3189",
|
||||
"rev": "a7d95e2b0029b8ee30facbe664b62968c59b46a6",
|
||||
"sha256": "0vprwa4h794bjd92arjnzdm8lb8mg3xvpfmqbk723zcxnvmpnafn",
|
||||
"type": "tarball",
|
||||
"url": "https://github.com/NixOS/nixpkgs/archive/6c43a3495a11e261e5f41e5d7eda2d71dae1b2fe.tar.gz",
|
||||
"url": "https://github.com/NixOS/nixpkgs/archive/a7d95e2b0029b8ee30facbe664b62968c59b46a6.tar.gz",
|
||||
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user