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

How serve 404 into static file for example index.html or 404.html #62

Open
Alsmile opened this issue Dec 23, 2015 · 2 comments
Open

How serve 404 into static file for example index.html or 404.html #62

Alsmile opened this issue Dec 23, 2015 · 2 comments

Comments

@Alsmile
Copy link

Alsmile commented Dec 23, 2015

mount.mount("/", staticfile::Static::new(Path::new("../assets/index.html")));

I hope it serve the static file when the Path is file. (fn Path::is_file(&self) -> bool)
/ => index.html
/404 => index.html

more :
https://github.com/rackt/react-router/blob/latest/docs/guides/basics/Histories.md#configuring-your-server

@dashed
Copy link

dashed commented Dec 26, 2015

I'm wondering how to do this as well.

@dashed
Copy link

dashed commented Dec 26, 2015

@Alsmile This may interest you.


I glanced at the source code of staticfile and used the following, in my opinion, hacky approach; which was adapted from https://github.com/iron/router/blob/master/examples/custom_404.rs

This works for my js app that uses html5 (pop/push)state:

struct Custom404 {
    staticfile: Static
}

impl AfterMiddleware for Custom404 {
    fn catch(&self, req: &mut Request, err: IronError) -> IronResult<Response> {

        // TODO: so hacky. need better alternative
        req.url.path = vec!["index.html".to_string()];

        return self.staticfile.handle(req);
        // return Ok(Response::with((status::NotFound, "404 Not Found")));
    }
}

// ...

    let custom_404 = Custom404 {
        staticfile: Static::new(app_path)
    };

    log_chain.link_after(custom_404);

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

No branches or pull requests

2 participants