Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nested WAI Applications under Scotty Routes #233

Merged
merged 9 commits into from
Sep 23, 2023
Merged

Conversation

sordina
Copy link
Contributor

@sordina sordina commented Oct 24, 2019

This PR adds a new nested handler that allows you to place an entire WAI Application under a Scotty route.

Let me know if this implementation fits!

Simple Example:

simpleApp :: Application
simpleApp _ respond = do
    putStrLn "I've done some IO here"
    respond $ responseLBS
        status200
        [("Content-Type", "text/plain")]
        "Hello, Web!"

main :: IO ()
main = do
  scotty 3000 $ do
    get "/simple" $ nested simpleApp

Reference:

  • Spec included under describe nested in ScottySpec.hs.
  • Examples included under examples/nested.hs

@sordina
Copy link
Contributor Author

sordina commented Oct 24, 2019

Looks like some of the apt-get CI commands are failing?

scottApp = scottyApp $ do

get "/" $ do
html $ mconcat ["<h1>Scotty, bean me up!</h1>"]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bean

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😆

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ocramz updated to beam

Copy link
Collaborator

@ocramz ocramz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think introducing 'nested' is a nice addition. @sordina could you add a test for this as well? Edit: and a Changelog entry as well please.

@sordina
Copy link
Contributor Author

sordina commented Jul 7, 2023

Noticed this warning when compiling:

Web/Scotty/Internal/Types.hs:168:5: warning: [-Wnoncanonical-monad-instances]
    Noncanonical ‘return’ definition detected
    in the instance declaration for ‘Monad (ActionT e m)’.
    ‘return’ will eventually be removed in favour of ‘pure’
    Either remove definition for ‘return’ (recommended) or define as ‘return = pure’
    See also: https://gitlab.haskell.org/ghc/ghc/-/wikis/proposal/monad-of-no-return
    |
168 |     return = ActionT . return

@ocramz
Copy link
Collaborator

ocramz commented Jul 7, 2023 via email

@sordina
Copy link
Contributor Author

sordina commented Jul 7, 2023

@ocramz I've added a spec that matches the simple example from examples/nested.hs.

@ocramz
Copy link
Collaborator

ocramz commented Jul 7, 2023

wyt @fumieval is this good to merge?

Comment on lines +378 to +379
_ <- liftAndCatchIO $ app r (\res -> putMVar ref res >> return ResponseReceived)
res <- liftAndCatchIO $ readMVar ref
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this catch?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it seems 'app' could put a landmine inside the MVar so.. I think so?

Copy link
Collaborator

@ocramz ocramz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a good PR I think

Comment on lines +378 to +379
_ <- liftAndCatchIO $ app r (\res -> putMVar ref res >> return ResponseReceived)
res <- liftAndCatchIO $ readMVar ref
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it seems 'app' could put a landmine inside the MVar so.. I think so?

@ocramz
Copy link
Collaborator

ocramz commented Sep 23, 2023

@sordina once you're able to add an entry to the Changelog I'll gladly merge. Thank you!

@sordina
Copy link
Contributor Author

sordina commented Sep 23, 2023

@ocramz Added a changelog entry under the next heading

Copy link
Collaborator

@ocramz ocramz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@ocramz ocramz merged commit 7e8739d into scotty-web:master Sep 23, 2023
5 checks passed
@ocramz
Copy link
Collaborator

ocramz commented Sep 23, 2023

@sordina Thank you! all good 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants