Skip to content

Commit d8f9f86

Browse files
committed
init
0 parents  commit d8f9f86

File tree

8 files changed

+223
-0
lines changed

8 files changed

+223
-0
lines changed

.gitignore

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
2+
3+
# Created by https://www.gitignore.io/api/haskell,emacs
4+
5+
### Haskell ###
6+
dist
7+
dist-*
8+
cabal-dev
9+
*.o
10+
*.hi
11+
*.chi
12+
*.chs.h
13+
*.dyn_o
14+
*.dyn_hi
15+
.hpc
16+
.hsenv
17+
.cabal-sandbox/
18+
cabal.sandbox.config
19+
*.prof
20+
*.aux
21+
*.hp
22+
*.eventlog
23+
.stack-work/
24+
cabal.project.local
25+
.HTF/
26+
27+
28+
### Emacs ###
29+
# -*- mode: gitignore; -*-
30+
*~
31+
\#*\#
32+
/.emacs.desktop
33+
/.emacs.desktop.lock
34+
*.elc
35+
auto-save-list
36+
tramp
37+
.\#*
38+
39+
# Org-mode
40+
.org-id-locations
41+
*_archive
42+
43+
# flymake-mode
44+
*_flymake.*
45+
46+
# eshell files
47+
/eshell/history
48+
/eshell/lastdir
49+
50+
# elpa packages
51+
/elpa/

LICENSE

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
Copyright (c) 2022, Gil Mizrahi
2+
3+
All rights reserved.
4+
5+
Redistribution and use in source and binary forms, with or without
6+
modification, are permitted provided that the following conditions are met:
7+
8+
* Redistributions of source code must retain the above copyright
9+
notice, this list of conditions and the following disclaimer.
10+
11+
* Redistributions in binary form must reproduce the above
12+
copyright notice, this list of conditions and the following
13+
disclaimer in the documentation and/or other materials provided
14+
with the distribution.
15+
16+
* Neither the name of Gil Mizrahi nor the names of other
17+
contributors may be used to endorse or promote products derived
18+
from this software without specific prior written permission.
19+
20+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24+
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28+
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

app/Main.hs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import qualified Bulletin
2+
3+
main :: IO ()
4+
main = Bulletin.main

readme.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Building a bulletin board using Haskell, twain and friends
2+
3+
Check out the [blog post](https://gilmi.me/blog/post/2020/12/05/scotty-bulletin-board) for the scotty tutorial.
4+
This version uses [twain](https://hackage.haskell.org/package/twain) instead.
5+
6+
## Run with
7+
8+
9+
```sh
10+
stack build && stack run
11+
```
12+
13+
## Static executable
14+
15+
To compile a static executable using docker, uncomment the relevant lines in the `stack.yaml` file,
16+
and rebuild with `stack build`.

src/Bulletin.hs

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
{-# language OverloadedStrings #-}
2+
3+
-- | A bulletin board app built with twain.
4+
module Bulletin where
5+
6+
import qualified Web.Twain as Twain
7+
import Network.Wai.Handler.Warp (run, Port)
8+
9+
-- | Entry point. Starts a bulletin-board server at port 3000.
10+
main :: IO ()
11+
main = runServer 3000
12+
13+
-- | Run a bulletin-board server at at specific port.
14+
runServer :: Port -> IO ()
15+
runServer port = do
16+
putStrLn $ unwords
17+
[ "Running bulletin board app at"
18+
, "http://localhost:" <> show port
19+
, "(ctrl-c to quit)"
20+
]
21+
run port mkApp
22+
23+
-- | Bulletin board application description.
24+
mkApp :: Twain.Application
25+
mkApp =
26+
foldr ($)
27+
(Twain.notFound $ Twain.send $ Twain.text "Error: not found.")
28+
routes
29+
30+
-- | Bulletin board routing.
31+
routes :: [Twain.Middleware]
32+
routes =
33+
-- Our main page, which will display all of the bulletins
34+
[ Twain.get "/" $
35+
Twain.send $ Twain.text "not yet implemented"
36+
37+
-- A page for a specific post
38+
, Twain.get "/post/:id" $
39+
Twain.send $ Twain.text "not yet implemented"
40+
41+
-- A page for creating a new post
42+
, Twain.get "/new" $
43+
Twain.send $ Twain.text "not yet implemented"
44+
45+
-- A request to submit a new page
46+
, Twain.post "/new" $
47+
Twain.send $ Twain.text "not yet implemented"
48+
49+
-- A request to delete a specific post
50+
, Twain.post "/post/:id/delete" $
51+
Twain.send $ Twain.text "not yet implemented"
52+
]

stack.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
resolver: nightly-2022-04-06
2+
3+
# uncomment for static executables
4+
# docker:
5+
# enable: true
6+
# image: utdemir/ghc-musl:v24-ghc922
7+
8+
packages:
9+
- .
10+
11+
extra-deps:
12+
- twain-2.1.0.0
13+
14+
allow-newer: true

stack.yaml.lock

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# This file was autogenerated by Stack.
2+
# You should not edit this file by hand.
3+
# For more information, please see the documentation at:
4+
# https://docs.haskellstack.org/en/stable/lock_files
5+
6+
packages:
7+
- completed:
8+
hackage: twain-2.1.0.0@sha256:9b434a5290791ab370845ded0d2167377cdc1478a592b87c5f5a9d499d069ba3,1864
9+
pantry-tree:
10+
size: 500
11+
sha256: 09cd5490f751e8740f294483d02987a2a387b7dfd4b0db0b0d66c9cd391a9d48
12+
original:
13+
hackage: twain-2.1.0.0
14+
snapshots:
15+
- completed:
16+
size: 545843
17+
url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/nightly/2022/4/6.yaml
18+
sha256: e59512928378e2411fea0269b3a658e31c8b24c9824dc213361dcce50a2b3f29
19+
original: nightly-2022-04-06

twain-bulletin-app.cabal

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: twain-bulletin-app
2+
version: 0.1.0.0
3+
synopsis: A simple bulletin board web app using twain
4+
description: Please see readme.md
5+
homepage: https://github.com/soupi/learn-twain-bulletin-app
6+
license-file: LICENSE
7+
author: Gil Mizrahi
8+
maintainer: gilmi@posteo.net
9+
copyright: 2022 Gil Mizrahi
10+
category: Web
11+
build-type: Simple
12+
cabal-version: >=1.10
13+
extra-source-files: readme.md
14+
15+
library
16+
hs-source-dirs: src
17+
exposed-modules: Bulletin
18+
19+
ghc-options: -Wall -fno-warn-type-defaults
20+
default-language: Haskell2010
21+
build-depends: base >= 4.7 && < 5
22+
, text >= 2
23+
, containers
24+
, time
25+
, stm
26+
, twain >= 2.1.0.0
27+
, warp
28+
, wai-extra
29+
, lucid
30+
31+
executable bulletin-app
32+
hs-source-dirs: app
33+
main-is: Main.hs
34+
default-language: Haskell2010
35+
ghc-options: -Wall -static -optl-static -optl-pthread -fPIC -O -threaded -rtsopts -with-rtsopts=-N
36+
build-depends: base >= 4.7 && < 5
37+
, twain-bulletin-app

0 commit comments

Comments
 (0)