init sampu

This commit is contained in:
James Eversole 2024-02-18 10:37:40 -06:00
commit 3e81ea8fec
9 changed files with 222 additions and 0 deletions

11
.gitignore vendored Normal file
View File

@ -0,0 +1,11 @@
*.swp
*~
.env
.stack-work/
Dockerfile
WD
bin/
data/
dist*
docker-stack.yml
result

80
flake.lock generated Normal file
View File

@ -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
}

28
flake.nix Normal file
View File

@ -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;
};
};
}

29
sampu.cabal Normal file
View File

@ -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

31
src/Core/HTTP.hs Normal file
View File

@ -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

17
src/Core/Handlers.hs Normal file
View File

@ -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"

7
src/Core/Rendering.hs Normal file
View File

@ -0,0 +1,7 @@
module Core.Rendering where
import Lucid
import Data.ByteString.Lazy (ByteString)
twain :: Html () -> ByteString
twain = renderBS

6
src/Main.hs Normal file
View File

@ -0,0 +1,6 @@
module Main where
import qualified Core.HTTP as Core
main :: IO ()
main = Core.main

13
src/Templates/Base.hs Normal file
View File

@ -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"