Comments (6)
@nixorn The idea looks legit. You indeed need to use hoistServerWithContext
function. But instead of nt
you should implement function like:
runAppAsHandler :: Env -> App a -> Handler a
And use it instead. Some example from our work:
server :: AppEnv -> Server API
server env = hoistServerWithContext
(Proxy @API)
(Proxy @AuthContextHandlers)
(runAppAsHandler env)
(toServant mpowerServer)
application :: AppEnv -> Application
application env = serveWithContext (Proxy @API) (authServerContext env) (server env)
authHandler :: AppEnv -> AuthHandler Request ()
authHandler env = mkAuthHandler (runAppAsHandler env . handler)
where
handler :: Request -> App ()
-- the custom monad here is called App and the environment from ReaderT is called AppEnv
from hintman.
Couldn't we already integrate the existing context into a monad for servant, and then add the Config to that context in another issue?
from hintman.
@cronokirby Well, I don't think that existing Context
should be used as application environment. For example, port
is not useful in the environment. So usually CLI arguments are called Options
, and then there's function that takes CLI options, configuration file options and combines them all into application Env
.
from hintman.
Ok I see
from hintman.
@chshersh got stuck with merging auth context + custom monad + generic servant https://github.com/kowainik/hintman/blob/10-custom-monad-in-servant/src/Hintman/Server.hs#L50
used mostly this doc https://haskell-servant.readthedocs.io/en/master/cookbook/hoist-server-with-context/HoistServerWithContext.html
Two errors. One:
Expected type: Handler x -> Handler x
Actual type: HintmanAppM x -> Handler x
As I understood it is about how to make generic servant return custom monad server instead of regular server.
Second:
• Couldn't match kind ‘*’ with ‘[*]’
When matching types
context0 :: [*]
HintmanAuthContext :: *
Expected type: Proxy context0
Actual type: Proxy HintmanAuthContext
• In the second argument of ‘hoistServerWithContext’, namely
‘(Proxy @HintmanAuthContext)’
In the second argument of ‘($)’, namely
‘hoistServerWithContext
hintmanApi
(Proxy @HintmanAuthContext)
(nt s)
(toServant hintmanServer)’
In the expression:
serveWithContext hintmanApi hintmanAuthServerContext
$ hoistServerWithContext
hintmanApi
(Proxy @HintmanAuthContext)
(nt s)
(toServant hintmanServer)
|
52 | $ hoistServerWithContext hintmanApi (Proxy @HintmanAuthContext) (nt s) (toServant hintmanServer)
No idea what is it, because I don't understand what is kind yet.
from hintman.
@chshersh still in trouble https://github.com/kowainik/hintman/blob/10-custom-monad-in-servant/src/Hintman/Server.hs
/home/nixorn/work/kowaink/hintman/src/Hintman/Server.hs:51:21: error:
• Couldn't match kind ‘*’ with ‘[*]’
When matching types
context0 :: [*]
HintmanAuthContext :: *
Expected type: Proxy context0
Actual type: Proxy HintmanAuthContext
• In the second argument of ‘hoistServerWithContext’, namely
‘(Proxy @HintmanAuthContext)’
In the second argument of ‘($)’, namely
‘hoistServerWithContext
(Proxy @HintmanAPI)
(Proxy @HintmanAuthContext)
(runAppAsHandler s)
(toServant hintmanServer)’
In the expression:
serveWithContext (Proxy @HintmanAPI) hintmanAuthServerContext
$ hoistServerWithContext
(Proxy @HintmanAPI)
(Proxy @HintmanAuthContext)
(runAppAsHandler s)
(toServant hintmanServer)
|
51 | (Proxy @HintmanAuthContext)
| ^^^^^^^^^^^^^^^^^^^^^^^^^
Can you explain why kinds different here? I can not get what ghc want from me)
from hintman.
Related Issues (20)
- Speed up tests by fetching PRs only once
- Add headers to Trailing* hints HOT 1
- Improve README
- Add tests for multiple hints in different hunks
- [RFC] Use multiline comment API to leave multiline comments HOT 2
- Display code duplication HLint suggestions better
- Log HLint errors
- [RFC] Rust support HOT 3
- [RFC] A lint for a lacking newline at the end of file HOT 1
- Investigate `endOfInputError` HOT 1
- Split file contents in the lines only once
- Use the correct base repo for downloading PR sources HOT 6
- Test consistency of `TrailingNewline` and `NoNewlineAtFileEnd`
- Bad credentials error
- Bump up GHC
- Support folders/files ignore
- Instructions how to uninstall HOT 1
- Use HLint 3.0
- Deprecation of some of the GitHub events
- Stylish-haskell and Ormolu support
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from hintman.