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

[3/?] Add ability to run code examples in the playground: Fetch tutorial snippet from URL by file name #205

Merged
merged 8 commits into from
May 28, 2024

Conversation

shaedrich
Copy link
Contributor

@shaedrich shaedrich commented Apr 22, 2024

See ponylang/pony-tutorial#340

Warning

Will only work, after #222 has been merged.

Example: https://playground.ponylang.io/?snippet=hello-world-main.pony

If we add .layer(CorsLayer::permissive()) here, we could even call the API from the tutorial and display the result below the code block (apparently, this had already been done in 2014, when the API was still written in Python: 02d0a98):

.route("/evaluate.json", post(evaluate))

or, if we want to be a little more restrictive, it could look like this:

use http::HeaderValue;
use tower_http::cors::CorsLayer;

let layer = CorsLayer::new().allow_origin(
    "https://tutorial.ponylang.io".parse::<HeaderValue>().unwrap(),
);
let router = Router::new()
        .route(
            "/",
            get(|| async { static_html(include_bytes!("../static/web.html")) }),
        )
        .route("/evaluate.json", post(evaluate))
        .layer(layer)
        // ...

static/web.js Outdated Show resolved Hide resolved
Copy link
Contributor

@mfelsche mfelsche left a comment

Choose a reason for hiding this comment

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

This looks good, just the little typo.

Always happy to accept PRs to allow calls from tutorial.ponylang.io. I am a bit hesitant to allow CORS requests from everywhere, unless we have proper monitoring and alerting and the ability to rate-limit/block clients.

Co-authored-by: Matthias Wahl <[email protected]>
@jemc
Copy link
Member

jemc commented May 14, 2024

If you're ready, feel free to convert to "ready for review" status and we can merge it. Thanks!

@shaedrich shaedrich changed the title [2/?] Add ability to run code examples in the playground: Fetch tutorial snippet from URL by file name [3/?] Add ability to run code examples in the playground: Fetch tutorial snippet from URL by file name May 20, 2024
@jemc jemc removed the discuss during sync Should be discussed during an upcoming sync label May 21, 2024
@ponylang-main ponylang-main added the discuss during sync Should be discussed during an upcoming sync label May 22, 2024
@shaedrich shaedrich marked this pull request as ready for review May 22, 2024 16:56
@jemc
Copy link
Member

jemc commented May 25, 2024

Looks like this has conflicts from merging #222 that need to be resolved. It wasn't straightforward enough for me to feel good about resolving it in the web editor without any testing.

@shaedrich
Copy link
Contributor Author

@jemc Conflicts resolved

static/web.js Outdated Show resolved Hide resolved
@jemc
Copy link
Member

jemc commented May 28, 2024

(Also it looks like the branch still has conflicts ❓ )

@shaedrich
Copy link
Contributor Author

shaedrich commented May 28, 2024

@jemc What gives you that impression? I don't see any pending conflicts

…ang/pony-tutorial

since it was meant to be used by ponylang/ponyc

Co-authored-by: Joe Eli McIlvain <[email protected]>
@shaedrich shaedrich requested a review from jemc May 28, 2024 18:27
@jemc
Copy link
Member

jemc commented May 28, 2024

Hmmm... I guess it doesn't have conflicts. Maybe I misunderstood something I saw in the GitHub UI? But I'm not seeing it now.

@jemc jemc merged commit 2c46224 into ponylang:main May 28, 2024
7 checks passed
@ponylang-main ponylang-main removed the discuss during sync Should be discussed during an upcoming sync label May 28, 2024
@shaedrich shaedrich deleted the patch-1 branch May 29, 2024 05:54
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.

None yet

4 participants