diff options
| author | Andrew Guschin <guschin.drew@gmail.com> | 2023-03-05 13:45:37 +0400 |
|---|---|---|
| committer | Andrew Guschin <guschin.drew@gmail.com> | 2023-03-05 13:47:41 +0400 |
| commit | a0e8e5a91d15ed8c79f4a1b5914d3a6242c0cbd3 (patch) | |
| tree | 76f76788523a16c0db8cb8f3a90b23912acd37d4 | |
| parent | dd73de2e563c332c5a90bb21c5c7e6cbebc0ab86 (diff) | |
Migrated project to cabal
| -rw-r--r-- | .gitignore | 4 | ||||
| -rw-r--r-- | LICENSE | 26 | ||||
| -rw-r--r-- | Setup.hs | 2 | ||||
| -rw-r--r-- | app/Main.hs (renamed from Main.hs) | 0 | ||||
| -rw-r--r-- | app/Routes.hs (renamed from Routes.hs) | 0 | ||||
| -rw-r--r-- | app/Settings.hs (renamed from Settings.hs) | 0 | ||||
| -rw-r--r-- | app/Views.hs (renamed from Views.hs) | 0 | ||||
| -rw-r--r-- | app/Web/Http.hs (renamed from Web/Http.hs) | 0 | ||||
| -rw-r--r-- | app/Web/Request.hs (renamed from Web/Request.hs) | 0 | ||||
| -rw-r--r-- | app/Web/Response.hs (renamed from Web/Response.hs) | 0 | ||||
| -rw-r--r-- | app/Web/Router.hs (renamed from Web/Router.hs) | 2 | ||||
| -rw-r--r-- | app/Web/Utils.hs (renamed from Web/Utils.hs) | 0 | ||||
| -rw-r--r-- | haskell-web.cabal | 60 | ||||
| -rw-r--r-- | net/Client.hs | 30 | ||||
| -rw-r--r-- | net/Server.hs | 65 | ||||
| -rw-r--r-- | net/client.hs | 30 | ||||
| -rw-r--r-- | net/server.hs | 42 | ||||
| -rw-r--r-- | stack.yaml | 67 |
18 files changed, 60 insertions, 268 deletions
@@ -1,4 +1,2 @@ -.stack-work +.* dist-newstyle -*.save* -*.lock
\ No newline at end of file @@ -0,0 +1,26 @@ +Copyright (c) 2023, Andrew Guschin +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are +met: + +1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + +2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the + distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/Setup.hs b/Setup.hs deleted file mode 100644 index 9a994af..0000000 --- a/Setup.hs +++ /dev/null @@ -1,2 +0,0 @@ -import Distribution.Simple -main = defaultMain diff --git a/Routes.hs b/app/Routes.hs index 3dbb3aa..3dbb3aa 100644 --- a/Routes.hs +++ b/app/Routes.hs diff --git a/Settings.hs b/app/Settings.hs index 0d55606..0d55606 100644 --- a/Settings.hs +++ b/app/Settings.hs diff --git a/Web/Http.hs b/app/Web/Http.hs index 92cb043..92cb043 100644 --- a/Web/Http.hs +++ b/app/Web/Http.hs diff --git a/Web/Request.hs b/app/Web/Request.hs index 71dc421..71dc421 100644 --- a/Web/Request.hs +++ b/app/Web/Request.hs diff --git a/Web/Response.hs b/app/Web/Response.hs index 3c393ad..3c393ad 100644 --- a/Web/Response.hs +++ b/app/Web/Response.hs diff --git a/Web/Router.hs b/app/Web/Router.hs index 234f30a..5e014d9 100644 --- a/Web/Router.hs +++ b/app/Web/Router.hs @@ -11,7 +11,7 @@ data Route = Route (Request -> IO Response) Text Method resolve :: [Route] -> Request -> IO Response resolve [] _ = return notFoundResponse -resolve (Route callback routeUrl _ : routerTable) req @ (Request _ url _) = +resolve (Route callback routeUrl _ : routerTable) req@(Request _ url _) = if url == routeUrl then callback req else resolve routerTable req diff --git a/Web/Utils.hs b/app/Web/Utils.hs index 97bc512..97bc512 100644 --- a/Web/Utils.hs +++ b/app/Web/Utils.hs diff --git a/haskell-web.cabal b/haskell-web.cabal index 9fd655e..6570c2f 100644 --- a/haskell-web.cabal +++ b/haskell-web.cabal @@ -1,31 +1,35 @@ -cabal-version: >=1.10 --- Initial package description 'haskell-web.cabal' generated by 'cabal --- init'. For further documentation, see --- http://haskell.org/cabal/users-guide/ +cabal-version: 3.0 -name: haskell-web -version: 0.1.0.0 -author: Andrew -maintainer: saintruler@gmail.com -build-type: Simple +name: haskell-web +version: 0.1.0.1 +license: BSD-2-Clause +license-file: LICENSE +author: Andrew Guschin +maintainer: guschin.drew@gmail.com +build-type: Simple + +common warnings + ghc-options: -Wall executable haskell-web - main-is: Main.hs - other-modules: - Web.Http - , Web.Request - , Web.Response - , Web.Router - , Web.Utils - , Views - , Routes - , Settings - -- other-extensions: - build-depends: - base >=4.14 && <4.15 - , text - , http-types - , bytestring - , network - -- hs-source-dirs: - default-language: Haskell2010 + -- Import common warning flags. + import: warnings + hs-source-dirs: app + default-language: Haskell2010 + + main-is: Main.hs + other-modules: + Web.Http + , Web.Request + , Web.Response + , Web.Router + , Web.Utils + , Views + , Routes + , Settings + build-depends: + base ^>=4.17.0.0 + , text + , http-types + , bytestring + , network diff --git a/net/Client.hs b/net/Client.hs deleted file mode 100644 index 863df6e..0000000 --- a/net/Client.hs +++ /dev/null @@ -1,30 +0,0 @@ -{-# LANGUAGE OverloadedStrings #-} --- Echo client program -module Main (main) where - -import qualified Control.Exception as E -import qualified Data.ByteString.Char8 as C -import Network.Socket -import Network.Socket.ByteString (recv, sendAll) - -main :: IO () -main = runTCPClient "127.0.0.1" "3000" $ \s -> do - sendAll s "Hello, world!" - msg <- recv s 1024 - putStr "Received: " - C.putStrLn msg - --- from the "network-run" package. -runTCPClient :: HostName -> ServiceName -> (Socket -> IO a) -> IO a -runTCPClient host port client = withSocketsDo $ do - addr <- resolve - E.bracket (open addr) close client - where - resolve = do - let hints = defaultHints { addrSocketType = Stream } - head <$> getAddrInfo (Just hints) (Just host) (Just port) - open addr = do - sock <- socket (addrFamily addr) (addrSocketType addr) (addrProtocol addr) - connect sock $ addrAddress addr - return sock - diff --git a/net/Server.hs b/net/Server.hs deleted file mode 100644 index 0e53330..0000000 --- a/net/Server.hs +++ /dev/null @@ -1,65 +0,0 @@ --- Echo server program -module Main (main) where - -import Control.Concurrent (forkFinally) -import qualified Control.Exception as E -import Control.Monad (unless, forever, void) - -import qualified Data.ByteString as S -import qualified Data.Text as T -import Data.Text.Encoding (encodeUtf8) - -import Network.Socket -import Network.Socket.ByteString (recv, sendAll) - -join :: String -> [String] -> String -join delim [] = "" -join delim (s : []) = s -join delim (s : rest) = - s ++ delim ++ join delim rest - -packStr :: String -> S.ByteString -packStr = encodeUtf8 . T.pack - -(+++) = S.append - -response = join "\n" - [ "HTTP/1.1 200 OK" - , "Content-Type: text/html; charset=utf-8" - , "Connection: keep-alive" - , "" - , "<i>PRIVET</i>" - ] - -main :: IO () -main = runTCPServer Nothing "3000" talk - where - talk s = do - msg <- recv s 1024 - print msg - unless (S.null msg) $ do - sendAll s (packStr response) - talk s - --- from the "network-run" package. -runTCPServer :: Maybe HostName -> ServiceName -> (Socket -> IO a) -> IO a -runTCPServer mhost port server = withSocketsDo $ do - addr <- resolve - E.bracket (open addr) close loop - where - resolve = do - let hints = defaultHints { - addrFlags = [AI_PASSIVE] - , addrSocketType = Stream - } - head <$> getAddrInfo (Just hints) mhost (Just port) - open addr = do - sock <- socket (addrFamily addr) (addrSocketType addr) (addrProtocol addr) - setSocketOption sock ReuseAddr 1 - withFdSocket sock $ setCloseOnExecIfNeeded - bind sock $ addrAddress addr - listen sock 1024 - return sock - loop sock = forever $ do - (conn, _peer) <- accept sock - void $ forkFinally (server conn) (const $ gracefulClose conn 5000) diff --git a/net/client.hs b/net/client.hs deleted file mode 100644 index 863df6e..0000000 --- a/net/client.hs +++ /dev/null @@ -1,30 +0,0 @@ -{-# LANGUAGE OverloadedStrings #-} --- Echo client program -module Main (main) where - -import qualified Control.Exception as E -import qualified Data.ByteString.Char8 as C -import Network.Socket -import Network.Socket.ByteString (recv, sendAll) - -main :: IO () -main = runTCPClient "127.0.0.1" "3000" $ \s -> do - sendAll s "Hello, world!" - msg <- recv s 1024 - putStr "Received: " - C.putStrLn msg - --- from the "network-run" package. -runTCPClient :: HostName -> ServiceName -> (Socket -> IO a) -> IO a -runTCPClient host port client = withSocketsDo $ do - addr <- resolve - E.bracket (open addr) close client - where - resolve = do - let hints = defaultHints { addrSocketType = Stream } - head <$> getAddrInfo (Just hints) (Just host) (Just port) - open addr = do - sock <- socket (addrFamily addr) (addrSocketType addr) (addrProtocol addr) - connect sock $ addrAddress addr - return sock - diff --git a/net/server.hs b/net/server.hs deleted file mode 100644 index a9bec82..0000000 --- a/net/server.hs +++ /dev/null @@ -1,42 +0,0 @@ --- Echo server program -module Main (main) where - -import Control.Concurrent (forkFinally) -import qualified Control.Exception as E -import Control.Monad (unless, forever, void) -import qualified Data.ByteString as S -import Network.Socket -import Network.Socket.ByteString (recv, sendAll) - -main :: IO () -main = runTCPServer Nothing "3000" talk - where - talk s = do - msg <- recv s 1024 - unless (S.null msg) $ do - sendAll s msg - talk s - --- from the "network-run" package. -runTCPServer :: Maybe HostName -> ServiceName -> (Socket -> IO a) -> IO a -runTCPServer mhost port server = withSocketsDo $ do - addr <- resolve - E.bracket (open addr) close loop - where - resolve = do - let hints = defaultHints { - addrFlags = [AI_PASSIVE] - , addrSocketType = Stream - } - head <$> getAddrInfo (Just hints) mhost (Just port) - open addr = do - sock <- socket (addrFamily addr) (addrSocketType addr) (addrProtocol addr) - setSocketOption sock ReuseAddr 1 - withFdSocket sock $ setCloseOnExecIfNeeded - bind sock $ addrAddress addr - listen sock 1024 - return sock - loop sock = forever $ do - (conn, _peer) <- accept sock - void $ forkFinally (server conn) (const $ gracefulClose conn 5000) - diff --git a/stack.yaml b/stack.yaml deleted file mode 100644 index 43c8738..0000000 --- a/stack.yaml +++ /dev/null @@ -1,67 +0,0 @@ -# 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: -# https://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 -# -# The location of a snapshot can be provided as a file or url. Stack assumes -# a snapshot provided as a file might change, whereas a url resource does not. -# -# resolver: ./custom-snapshot.yaml -# resolver: https://example.com/snapshots/2018-01-01.yaml -resolver: - url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/nightly/2020/11/23.yaml - -# 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 -# subdirs: -# - auto-update -# - wai -packages: -- . -# Dependency packages to be pulled from upstream that are not in the resolver. -# These entries can reference officially published versions as well as -# forks / in-progress versions pinned to a git hash. For example: -# -# extra-deps: -# - acme-missiles-0.3 -# - git: https://github.com/commercialhaskell/stack.git -# commit: e7b331f14bcffb8367cd58fbfc8b40ec7642100a -# -# extra-deps: [] - -# Override default flag values for local packages and extra-deps -# flags: {} - -# Extra package databases containing global packages -# 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: ">=2.5" -# -# 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 |