GithubHelp home page GithubHelp logo

Comments (4)

seanmonstar avatar seanmonstar commented on May 6, 2024

I understand the use case, and would like to support it. The path filter could be changed to allow passing a String or something... but that would then prevent it from being impl Filter + Copy.

As a stopgap, you can probably achieve what you want by making using of warp::path::param::<String>(). You could then create dynamic filters like this:

let arg_path = clap.arg_something();

let clapped_path = warp::path::param()
    .and_then(move |param: String| {
        if param == arg_path {
            Ok(())
        } else {
            Err(warp::reject::not_found())
        }
    });

from warp.

erikdesjardins avatar erikdesjardins commented on May 6, 2024

Another workaround: create a &'static str at runtime with Box::leak(string.into_boxed_str()).
It will leak the string's memory, but if the server runs until process termination that's not a big deal.

from warp.

phyber avatar phyber commented on May 6, 2024

Thanks for the help here, I've landed on this for the time being:

let telemetry_path = matches
    .value_of("WEB_TELEMETRY_PATH")
    .unwrap();
let telemetry_path = telemetry_path.to_owned();

let telemetry = warp::get2()
    .and(warp::path::param::<String>())
    .and_then(move |param: String| {
        let mut get_path = "/".to_owned();
        get_path.push_str(&param);

        if get_path == telemetry_path {
            Ok(())
        }
        else {
            Err(warp::reject::not_found())
        }
    });
let telemetry = telemetry.and_then(metrics);
let routes = telemetry;
let server = warp::serve(routes);

This is working fine and I learned a little more about move in the process. Thanks again.

from warp.

jsdw avatar jsdw commented on May 6, 2024

I ran into a related issue (working with warp on master which now supports async/await).

I'd like to be able to mount my app under an arbitrary path (eg "/foo/bar/wibble") so that it can happily be configured to coexist with other apps running (for example if I was to deploy it to k8s).

Using the Box::leak trick gets me as far as being able to configure a single path piece (eg "/foo") to mount the app underneath, but since slashes aren't allowed I can't supply a full path to mount the app underneath.

I couldn't get the custom-filter approach to work at all, but it would have suffered from the same issue of only matching against a single piece of the path anyway.

It would be nice to be able to use Strings for paths in general, and also for slashes to work (perhaps using a new filter like full_path or somesuch? I'm not fully sure why they don't work already).

from warp.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.