Initial commit
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
# Revision history for backend
|
||||
|
||||
## 0.1.0.0 -- YYYY-mm-dd
|
||||
|
||||
* First version. Released on an unsuspecting world.
|
||||
@@ -0,0 +1,10 @@
|
||||
FROM haskell:8
|
||||
WORKDIR /opt/backend
|
||||
RUN apt-get update
|
||||
RUN yes | apt-get install postgresql libpq-dev
|
||||
RUN cabal update
|
||||
COPY ./backend.cabal /opt/backend
|
||||
RUN cabal build --only-dependencies -j4
|
||||
COPY . /opt/backend
|
||||
RUN cabal install
|
||||
CMD ["backend"]
|
||||
@@ -0,0 +1,31 @@
|
||||
module Main where
|
||||
|
||||
import Happstack.Server
|
||||
import Control.Monad
|
||||
import Control.Exception
|
||||
import Database.HDBC
|
||||
import Database.HDBC.PostgreSQL (connectPostgreSQL)
|
||||
import Text.JSON
|
||||
|
||||
config = Conf {
|
||||
port = 80,
|
||||
validator = Nothing,
|
||||
logAccess = Just logMAccess,
|
||||
timeout = 30,
|
||||
threadGroup = Nothing
|
||||
}
|
||||
|
||||
getPostListing c = do
|
||||
select <- prepare c "SELECT * FROM posts;"
|
||||
execute select []
|
||||
result <- fetchAllRows select
|
||||
let posts = JSArray $ (map (\(t:s:c:[]) -> let (title, subtext, category) = (fromSql t, fromSql s, fromSql c) in showJSON $ toJSObject [("title", toJSString title), ("subtext", toJSString subtext), ("category", toJSString category)]) result) in
|
||||
return $ Just $ encode posts
|
||||
|
||||
main :: IO ()
|
||||
main = do
|
||||
c <- connectPostgreSQL "host=database user=blog password=root dbname=blog"
|
||||
simpleHTTP config $
|
||||
msum [ dir "v1" $ path $ \s -> case s of {"posts" -> require (getPostListing c) $ \posts -> ok posts ; _ -> notFound "Endpoint does not exist"}
|
||||
, notFound "Endpoint does not exist"
|
||||
]
|
||||
@@ -0,0 +1,34 @@
|
||||
cabal-version: 2.4
|
||||
name: backend
|
||||
version: 0.1.0.0
|
||||
|
||||
-- A short (one-line) description of the package.
|
||||
-- synopsis:
|
||||
|
||||
-- A longer description of the package.
|
||||
-- description:
|
||||
|
||||
-- A URL where users can report bugs.
|
||||
-- bug-reports:
|
||||
|
||||
-- The license under which the package is released.
|
||||
-- license:
|
||||
author: Xnoe
|
||||
maintainer: xnoe@xnoe.moe
|
||||
|
||||
-- A copyright notice.
|
||||
-- copyright:
|
||||
-- category:
|
||||
extra-source-files: CHANGELOG.md
|
||||
|
||||
executable backend
|
||||
main-is: Main.hs
|
||||
|
||||
-- Modules included in this executable, other than Main.
|
||||
-- other-modules:
|
||||
|
||||
-- LANGUAGE extensions used by modules in this package.
|
||||
-- other-extensions:
|
||||
build-depends: base ^>=4.14.3.0, happstack-server ^>=7.7.2, HDBC ^>= 2.4.0.4, HDBC-postgresql ^>= 2.3.2.4, json ^>= 0.10
|
||||
hs-source-dirs: app
|
||||
default-language: Haskell2010
|
||||
Reference in New Issue
Block a user