Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    Ryman
    @Ryman
    @euclio It should work yes, are you having trouble with it?
    Andy Russell
    @euclio
    @Ryman ok, I was, but I'll take another look
    Andy Russell
    @euclio
    hm, after another test it seems that my code is only using one of my static file handlers to try and find files
    Ryman
    @Ryman
    @euclio So the second isn't working? Can you share some example code?
    Andy Russell
    @euclio

    @Ryman Seems to be working now. I must have been using the API incorrectly. However, I found that StaticFilesHandler is not quite what I need. I'm trying to make a custom middleware that allows me to modify the path that static files are served from. Here's what I have (doesn't compile):

            server.utilize(middleware! { |request, response|
                let path = request.path_without_query().map(|path| {
                    path[1..].to_owned()
                });
    
                if let Some(path) = path {
                    let path = self.cwd.join(path);
                    match fs::metadata(&path) {
                        Ok(ref attr) if attr.is_file() => return response.send_file(&path),
                        Err(ref e) if e.kind() != NotFound => debug!("Error getting metadata \
                                                                      for file '{:?}': {:?}",
                                                                      path, e),
                        _ => {}
                    }
                };
            });

    self.cwd is a PathBuf. It's an attribute on a containing struct that is basically only responsible for starting the server.

    Ryman
    @Ryman
    @euclio It sounds like you might want to use the Mount middleware? https://github.com/nickel-org/nickel.rs/blob/master/examples/mount.rs#L20
    Andy Russell
    @euclio
    @Ryman I don't think so... Let me give some more context. I'm writing a markdown preview server that renders markdown files into HTML. I want to be able to render images, etc. in the markdown that have relative paths. I was using the StaticFilesHandler middleware to do this. The problem is that if the markdown being rendered is from a different directory, then I would have to change the middleware, which I'm not sure is possible after the server starts. My plan was to have custom middleware that queries the directory that the current markdown file is in, and then serves static files out of that. I'm running into problems with type inference and lifetimes with the middleware! macro though. The above code is basically what I want to do, where self.cwd is the directory that contains the markdown file.
    Ryman
    @Ryman
    If you have a public repo/branch though, it would be interesting to see if there's someway we could make the built in structures more flexible for the usecase.
    @euclio Got it, yeah sounds like you might need something custom or to emulate the mount in someway. The lifetime issues in the above I'm guessing is from self.cwd being in the closure? You'll need to wrap it in an Arc (and possible Mutex/RwLock) if you want to share it across threads (the handler may run across many threads)
    Andy Russell
    @euclio
    This message was deleted
    @Ryman Yeah, that's the problem. I think the issue is that self.cwd needs to be 'static. Now the question is how to do that.
    Ryman
    @Ryman
    @euclio does using std::sync::Arc not work for you?
    Andy Russell
    @euclio
    This message was deleted
    Andy Russell
    @euclio
    @Ryman yes it does! Can't believe I didn't think of that.
    野山菌
    @windyslove

    windys-OEM:~$ cargo install nickel -v
    Updating registry https://github.com/rust-lang/crates.io-index
    Downloading nickel v0.7.3
    Failed to download package nickel v0.7.3 from https://crates.io/api/v1/crates/nickel/0.7.3/download

    Caused by:
    Timeout was reached

    how to resolve this
    Andy Russell
    @euclio
    @windyslove probably a problem with your internet
    Denis Lisov
    @tanriol
    How does Nickel use threads? Does it use a fixed-size thread pool?
    I expect my server to have several long-running responses (proxying a data stream for hours). Do I need to somehow ensure that they don't occupy all threads and block new requests? The trivial "spawn a new thread and pass the Response to it" seems not to work.
    Simon Persson
    @SimonPersson
    @tanriol - It does use a fixed size thread pool, yes. There's an pull request that would enable you to add more threads, nickel-org/nickel.rs#309, but depending on how many connections you expect that might not be enough. In that case, you will have to wait for a change in hyper, discussed here: hyperium/hyper#395.
    Serejka
    @serejkaaa512
    Hello everyone. I've got a question - if i want to get param from request params, like this "/generator/:id/set_freq/:freq", where freq is float, i get all till "." For example if i send "3.5" - i get "3". Maybe someone has already done this, but i didn't find. Thanks.
    if using regex, all is ok.
    Denis Lisov
    @tanriol
    Does the middleware! macro intentionally prevent moving the Response into the closure with the restrict function? I'm trying to have a loop sending data inside the closure and getting errors about this.
    Ryman
    @Ryman
    @serejkaaa512 I think you're encountering the added :format parameter, you should be able to find the '.5' in req.param("format"), see here for example: https://github.com/nickel-org/nickel.rs/blob/master/examples/routing.rs#L26-L27
    @tanriol you should be able to use your loop and then return <MiddlewareResult> e.g. return res.send("") which will short circuit the macro and not call restrict
    Serejka
    @serejkaaa512
    @Ryman thanks. That works, but it's not obvious. :)
    Denis Lisov
    @tanriol
    @Ryman, found the cause. The argument of middleware!looks like a closure, but is actually used as a block; return and leaving out semicolon on the last line work in different ways. This point probably needs to be documented somewhere.
    Denis Lisov
    @tanriol
    Is anyone actually looking into #310 / #309 / #277 ? The latest one at least seems to be stalled for no reason...
    Simon Persson
    @SimonPersson
    @tanriol - We've been a bit inactive. I just went ahead and merged #310, once #309 is rewritten to use that I'll merge that as well.
    Ghost
    @ghost~56ba344de610378809c0a277
    Will the auth middleware be available anytime soon?
    Ryman
    @Ryman
    @snadon Sorry, we had an exploratory branch here: nickel-org/nickel-auth#1 but we've kind of let it.. rust If you'd like to review it to see if it's fit for your purposes that would probably help carry things along!
    Ghost
    @ghost~56ba344de610378809c0a277
    @Ryman Ok I'm gonna take a look thanks!
    Mathieu De Coster
    @m-decoster
    This message was deleted
    rvolgers
    @rvolgers
    Hi, are there some examples of using Nickel without coding all the handlers inline using the middleware! macro?
    I'm trying to have my handlers just be normal functions, but the lack of the Responder wrapping and the fact the NickelError wants to take ownership of the response means I literally cannot think of a way to use normal .map_err techniques to do error handling
    so how do I do error handling when not using the middleware! wrapper? am I missing something?
    rvolgers
    @rvolgers
    Here's an example of how verbose my error handling gets: http://pastebin.com/7jLAeCSL
    Regis Boudinot
    @selfup
    Quick question, just to see the level of interest. I am working on a JSON Key Value store, which would be great for something like nickel, and was wondering how interested you all would be? It's not quite ready yet, but we are getting close!
    Ryman
    @Ryman
    @selfup It sounds like an interesting project. Is there something nickel specific you need feedback about?
    Kevin King
    @kcking
    Has anyone used nickel to allow login with client ssl certs? I couldn't find an example or middleware
    Regis Boudinot
    @selfup

    @Ryman Just wanted to know if it was attractive enough for people who use nickle on small projects or micro-services.

    So far some of our read/writes (for basic unserialized json) are < 1 microsecond.

    The library itself handles serialization through serde, which is unfortunately geared towards nightly. But it offers developers to make very easy function calls and manipulate data as long as they have a basic schema of public facing structs so the library can infer the Type.

    Making it work with stable, will require some work, but we aren't ready to release just quite yet, so we shall cross that bridge when we get there.

    Everything so far is faster than I anticipated, so that is why I want to see the level of interest for a plug and play library that let's users have a flexible (however project bound) JSON Key Value Store.

    Here are some benchmarks: https://cloud.githubusercontent.com/assets/9837366/16293601/7be59d6c-38d8-11e6-9016-71d42932bc0f.png

    We have since changed the function names to make more sense. So take the names with a grain of salt for now haha :smile:

    Regis Boudinot
    @selfup
    Also, that benchmark is a bit old. It doesn't have the ~800ns unserialized JSON read/write for tables
    Ryman
    @Ryman
    @kcking I haven't heard anyone working on it, perhaps there's something available for hyper which could be adapted?
    I keep getting this error: thread '<unnamed>' panicked at 'Unclosed section', /home/dannyfritz/.cargo/registry/src/github.com-1ecc6299db9ec823/mustache-0.6.3/src/parser.rs:406
    Ryman
    @Ryman
    @dannyfritz The render method only supports mustache currently (I'm surprised the doccomment actually doesn't mention that). There's an open issue for adding handlebars if you'd like to follow: nickel-org/nickel.rs#305
    Danny Fritz
    @dannyfritz
    oooo. thanks!
    Sklopi
    @sklopi
    hi guys, i'm writing a postgresql session storage for my nickel.rs application. i'm asking myself why hyper is not reexported in nickel? i think it would be nice if i didn't have to import the exact version of hyper nickel is using
    Iban Eguia
    @Razican
    Hi! I have one question regarding templating. Can I create multiple templates and join them? I mean, one for header, one for footer... And then change the body template for each request. Oh, and can I use some sort of for loop to show multiple objects of the same type in the template engine?