Skip to content

Commit

Permalink
Add basic middleware skeletion
Browse files Browse the repository at this point in the history
For now just wrapping the basic postgrest application
without adding additional functionality from the middleware.
  • Loading branch information
nblumoe committed Jul 6, 2016
1 parent fc3eea2 commit fa09003
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 14 deletions.
27 changes: 26 additions & 1 deletion app/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,30 @@

module Main where

import PostgREST.Config (AppConfig (..),
readOptions)
import PostgREST.DbStructure

import PostgRESTOAuth

import qualified Hasql.Pool as P
import Data.IORef
import Data.String.Conversions (cs)

import Network.Wai.Handler.Warp


main :: IO ()
main = putStrLn "Not yet implemented"
main = do
conf <- readOptions
let port = configPort conf
pgConfig = cs $ configDatabase conf
poolConfig = configPool conf
appSettings = setPort port
. setServerName "postgrest"
$ defaultSettings
pool <- P.acquire (poolConfig, 10, pgConfig)
structure <- P.use pool $ getDbStructure (cs $ configSchema conf)
refDbStructure <- newIORef $ either (error.show) id structure
putStrLn $ "Listening on port " ++ show port
runSettings appSettings $ postgrestOAuthApp conf refDbStructure pool
14 changes: 14 additions & 0 deletions postgrest-oauth.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ library
exposed-modules: PostgRESTOAuth
ghc-options: -Wall
build-depends: base >= 4.7 && < 5
, hasql-pool
, postgresql-libpq
, postgrest >= 0.3 && < 0.4
, string-conversions
, wai
, warp
default-language: Haskell2010
default-extensions: OverloadedStrings

Expand All @@ -26,3 +32,11 @@ executable postgrest-oauth
main-is: Main.hs
default-language: Haskell2010
build-depends: base >= 4.7 && < 5
, hasql-pool
, postgresql-libpq
, postgrest >= 0.3 && < 0.4
, postgrest-oauth
, string-conversions
, wai
, warp
default-extensions: OverloadedStrings
19 changes: 18 additions & 1 deletion src/PostgRESTOAuth.hs
Original file line number Diff line number Diff line change
@@ -1 +1,18 @@
module PostgRESTOAuth where
module PostgRESTOAuth
( postgrestOAuthApp
) where

import qualified Hasql.Pool as H

import GHC.IORef
import PostgREST.App as PGR
import PostgREST.Config as PGR
import PostgREST.Types as PGR
import qualified Network.Wai as Wai

postgrestOAuthApp :: PGR.AppConfig
-> IORef PGR.DbStructure
-> H.Pool
-> Wai.Application
postgrestOAuthApp conf refDbStructure pool =
postgrest conf refDbStructure pool
27 changes: 15 additions & 12 deletions stack.yaml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# This file was automatically generated by 'stack init'
#
#
# Some commonly used options have been documented as comments in this file.
# For advanced use and comprehensive documentation of the format, please see:
# http://docs.haskellstack.org/en/stable/yaml_configuration/

# Resolver to choose a 'specific' stackage snapshot or a compiler version.
# A snapshot resolver dictates the compiler version and the set of packages
# to be used for project dependencies. For example:
#
#
# resolver: lts-3.5
# resolver: nightly-2015-09-21
# resolver: ghc-7.10.2
Expand All @@ -19,7 +19,7 @@ resolver: lts-6.6

# User packages to be built.
# Various formats can be used as shown in the example below.
#
#
# packages:
# - some-directory
# - https://example.com/foo/bar/baz-0.0.2.tar.gz
Expand All @@ -31,15 +31,18 @@ resolver: lts-6.6
# subdirs:
# - auto-update
# - wai
#
#
# A package marked 'extra-dep: true' will only be built if demanded by a
# non-dependency (i.e. a user package), and its test suites and benchmarks
# will not be run. This is useful for tweaking upstream packages.
packages:
- '.'
# Dependency packages to be pulled from upstream that are not in the resolver
# (e.g., acme-missiles-0.3)
extra-deps: []
extra-deps:
- hasql-pool-0.4.1
- hasql-transaction-0.4.5
- postgresql-error-codes-1
- postgrest-0.3.2.0
- Ranged-sets-0.3.0

# Override default flag values for local packages and extra-deps
flags: {}
Expand All @@ -49,18 +52,18 @@ extra-package-dbs: []

# Control whether we use the GHC we find on the path
# system-ghc: true
#
#
# Require a specific version of stack, using version ranges
# require-stack-version: -any # Default
# require-stack-version: ">=1.1"
#
#
# Override the architecture used by stack, especially useful on Windows
# arch: i386
# arch: x86_64
#
#
# Extra directories used by stack for building
# extra-include-dirs: [/path/to/dir]
# extra-lib-dirs: [/path/to/dir]
#
#
# Allow a newer minor version of GHC than the snapshot specifies
# compiler-check: newer-minor
# compiler-check: newer-minor

0 comments on commit fa09003

Please sign in to comment.