diff options
author | Yuchen Pei <hi@ypei.me> | 2022-10-05 11:54:57 +1100 |
---|---|---|
committer | Yuchen Pei <hi@ypei.me> | 2022-10-05 11:54:57 +1100 |
commit | 918dcdb602622af47f0607519b95c3aa2abab5ff (patch) | |
tree | b2c0b34ada776f2fa9cbcd0c3440d350c06190ce /app | |
parent | 0fc6e35633ff69a8ff08784d32623f794ccba37b (diff) |
Adding a greet api to get server info (currently only version)
Diffstat (limited to 'app')
-rw-r--r-- | app/Server.hs | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/app/Server.hs b/app/Server.hs index 1c9980d..e4efd36 100644 --- a/app/Server.hs +++ b/app/Server.hs @@ -48,7 +48,7 @@ import Data.IntervalMap.Interval (Interval(..), subsumes) import qualified Data.IntervalMap.Strict as IVM import qualified Data.List as L import qualified Data.Map.Strict as M -import Data.Maybe (fromMaybe, listToMaybe, mapMaybe) +import Data.Maybe (fromMaybe, mapMaybe) import qualified Data.Vector as V import qualified GHC.Compact as C import Data.Pagination @@ -67,7 +67,7 @@ import qualified Data.Text as T import qualified Data.Text.Encoding as TE import Data.Text.Lazy (toStrict) import Data.Text.Read(decimal) -import Data.Version (Version(..)) +import Data.Version (Version(..), showVersion) import GHC.Exts (Down(..), groupWith) import GHC.Generics (Generic) import qualified HaskellCodeExplorer.Types as HCE @@ -114,6 +114,7 @@ import Options.Applicative , strOption , switch ) +import qualified Paths_hcel (version) import Servant ( (:<|>)(..) , (:>) @@ -909,7 +910,8 @@ handleSync onError = -- Servant API -------------------------------------------------------------------------------- -type API = GetAllPackages +type API = Greet + :<|> GetAllPackages :<|> GetDefinitionSite :<|> GetExpressions :<|> GetReferences @@ -920,6 +922,8 @@ type API = GetAllPackages :<|> GetGlobalIdentifierE :<|> GetHoogleDocs +type Greet = "api" :> "greet" :> Get '[JSON] T.Text + type GetAllPackages = "api" :> "packages" :> Get '[JSON] AllPackages type GetDefinitionSite = "api" :> "definitionSite" @@ -1067,6 +1071,9 @@ data SourceFile = SourceFile instance A.ToJSON ReferenceWithSource instance A.ToJSON SourceFile +greet :: ReaderT Environment IO T.Text +greet = return $ T.pack $ showVersion Paths_hcel.version + getAllPackages :: ReaderT Environment IO AllPackages getAllPackages = asks envPackageVersions @@ -1853,7 +1860,8 @@ server env = hoistServer (Proxy :: Proxy API) toServantHandler - (getAllPackages :<|> + (greet :<|> + getAllPackages :<|> getDefinitionSite :<|> getExpressions :<|> getReferences :<|> |