commit 3e81ea8fec8c78ff676aa5890dbea2a1b223776e Author: James Eversole Date: Sun Feb 18 10:37:40 2024 -0600 init sampu diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..7088499 --- /dev/null +++ b/.gitignore @@ -0,0 +1,11 @@ +*.swp +*~ +.env +.stack-work/ +Dockerfile +WD +bin/ +data/ +dist* +docker-stack.yml +result diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..a76f607 --- /dev/null +++ b/flake.lock @@ -0,0 +1,80 @@ +{ + "nodes": { + "haskell-flake": { + "locked": { + "lastModified": 1707835791, + "narHash": "sha256-oQbDPHtver9DO8IJCBMq/TVbscCkxuw9tIfBBti71Yk=", + "owner": "srid", + "repo": "haskell-flake", + "rev": "5113f700d6e92199fbe0574f7d12c775bb169702", + "type": "github" + }, + "original": { + "owner": "srid", + "repo": "haskell-flake", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1701282334, + "narHash": "sha256-MxCVrXY6v4QmfTwIysjjaX0XUhqBbxTWWB4HXtDYsdk=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "057f9aecfb71c4437d2b27d3323df7f93c010b7e", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "23.11", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs-lib": { + "locked": { + "dir": "lib", + "lastModified": 1706550542, + "narHash": "sha256-UcsnCG6wx++23yeER4Hg18CXWbgNpqNXcHIo5/1Y+hc=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "97b17f32362e475016f942bbdfda4a4a72a8a652", + "type": "github" + }, + "original": { + "dir": "lib", + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "parts": { + "inputs": { + "nixpkgs-lib": "nixpkgs-lib" + }, + "locked": { + "lastModified": 1706830856, + "narHash": "sha256-a0NYyp+h9hlb7ddVz4LUn1vT/PLwqfrWYcHMvFB1xYg=", + "owner": "hercules-ci", + "repo": "flake-parts", + "rev": "b253292d9c0a5ead9bc98c4e9a26c6312e27d69f", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "repo": "flake-parts", + "type": "github" + } + }, + "root": { + "inputs": { + "haskell-flake": "haskell-flake", + "nixpkgs": "nixpkgs", + "parts": "parts" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..e22f581 --- /dev/null +++ b/flake.nix @@ -0,0 +1,28 @@ +{ + inputs = { + nixpkgs.url = "github:nixos/nixpkgs/23.11"; + haskell-flake.url = "github:srid/haskell-flake"; + parts.url = "github:hercules-ci/flake-parts"; + }; + outputs = inputs@{ self, nixpkgs, parts, ... }: + parts.lib.mkFlake { inherit inputs; } { + systems = nixpkgs.lib.systems.flakeExposed; + imports = [ inputs.haskell-flake.flakeModule ]; + + perSystem = { self', pkgs, ... }: { + haskellProjects.default = { + basePackages = pkgs.haskellPackages; + packages = { + http2.source = "3.0.3"; + }; + devShell = { + enable = true; + tools = hp: { fourmolu = hp.fourmolu; }; + hlsCheck.enable = true; + }; + }; + + packages.default = self'.packages.sampu; + }; + }; +} diff --git a/sampu.cabal b/sampu.cabal new file mode 100644 index 0000000..d0829dd --- /dev/null +++ b/sampu.cabal @@ -0,0 +1,29 @@ +cabal-version: 3.0 +name: sampu +version: 0.1.0 +license: ISC +author: James Eversole +maintainer: james@eversole.co +build-type: Simple + +common warnings + ghc-options: -Wall + +executable sampu + import: warnings + main-is: Main.hs + default-extensions: OverloadedStrings + build-depends: base + , bytestring >= 0.11.5.0 + , commonmark >= 0.2.4 + , lucid >= 2.11.0 + , twain >= 2.1.0.0 + , wai-extra >= 3.0 && < 3.2 + , warp == 3.3.25 + hs-source-dirs: src + other-modules: + Core.Handlers + Core.HTTP + Core.Rendering + Templates.Base + default-language: GHC2021 diff --git a/src/Core/HTTP.hs b/src/Core/HTTP.hs new file mode 100644 index 0000000..fa5ca46 --- /dev/null +++ b/src/Core/HTTP.hs @@ -0,0 +1,31 @@ +module Core.HTTP where + +import qualified Core.Handlers as Handle + +import Network.Wai.Middleware.RequestLogger (logStdoutDev) +import Network.Wai.Handler.Warp (Port, run) +import Web.Twain + +main :: IO () +main = do + run appPort $ + foldr ($) (notFound Handle.missing) app + +-- Combine our Preprocessor Middlewares and Routes to create an App +app :: [Middleware] +app = preProcessors ++ routes + +-- These Middleware are always executed before any routes are reached +preProcessors :: [Middleware] +preProcessors = [logStdoutDev] + +-- The application's core routes expressed as a list of WAI middlewares +routes :: [Middleware] +routes = + [ get "/" Handle.index + , get "/echo/:testParam" Handle.testRoute + ] + +-- This will be replaced with getEnv located in Configuration +appPort :: Port +appPort = 3000 diff --git a/src/Core/Handlers.hs b/src/Core/Handlers.hs new file mode 100644 index 0000000..a5f5227 --- /dev/null +++ b/src/Core/Handlers.hs @@ -0,0 +1,17 @@ +module Core.Handlers where + +import qualified Templates.Base as T +import Core.Rendering as R + +import Web.Twain + +index :: ResponderM a +index = send $ html $ R.twain T.baseNav + +testRoute :: ResponderM a +testRoute = do + testParam <- param "testParam" + send $ status status202 $ html $ "Testing echo parameter: " <> testParam + +missing :: ResponderM a +missing = send $ html "404 NOT FOUND" diff --git a/src/Core/Rendering.hs b/src/Core/Rendering.hs new file mode 100644 index 0000000..a488615 --- /dev/null +++ b/src/Core/Rendering.hs @@ -0,0 +1,7 @@ +module Core.Rendering where + +import Lucid +import Data.ByteString.Lazy (ByteString) + +twain :: Html () -> ByteString +twain = renderBS diff --git a/src/Main.hs b/src/Main.hs new file mode 100644 index 0000000..4820368 --- /dev/null +++ b/src/Main.hs @@ -0,0 +1,6 @@ +module Main where + +import qualified Core.HTTP as Core + +main :: IO () +main = Core.main diff --git a/src/Templates/Base.hs b/src/Templates/Base.hs new file mode 100644 index 0000000..6fccd6f --- /dev/null +++ b/src/Templates/Base.hs @@ -0,0 +1,13 @@ +module Templates.Base where + +import Lucid + +baseNav :: Html () +baseNav = doctypehtml_ $ do + head_ $ do + title_ getBlogTitle + link_ [rel_ "stylesheet", type_ "text/css", href_ "style.css"] + body_ $ do + h1_ "This will be a nav eventually." + where + getBlogTitle = "unimplemented getEnv"