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

Provide template servers that use 404-redirection #1108

Closed
1 of 3 tasks
hgzimmerman opened this issue Dec 4, 2019 · 3 comments
Closed
1 of 3 tasks

Provide template servers that use 404-redirection #1108

hgzimmerman opened this issue Dec 4, 2019 · 3 comments
Labels
A-examples Area: The examples A-yew-router Area: The yew-router crate

Comments

@hgzimmerman
Copy link
Member

Description

Because cargo web doesn't support serving the index.html content, some template servers should be provided in order to provide this functionality as well as to demonstrate how to implement it within their own server.

Servers should include:

  • Warp
  • Rocket
  • Actix-web
    and anything else someone is willing to contribute.

All servers should:

  • Optionally(?) host a REST API mounted under /api/.
    • Possibly have the ability to just always return index.html content if a endpoint doesn't exist (no api, just a file server).
  • Serve the index.html for anything not under /api/ instead of returning a 404 error.

per: #771

@thienpow
Copy link

thienpow commented Dec 7, 2019

For Warp Server

extern crate warp;

use warp::Filter;

#[tokio::main]
async fn main() {
    
    let index = warp::fs::dir("../rustcloud-landing/dist");
    let about = warp::path("about").and(warp::fs::dir("../rustcloud-landing/dist"));

    let routes = warp::get()
        .and(index
            .or(about)
        );
        
    warp::serve(routes).run(([127, 0, 0, 1], 3030)).await;
}

For the FrontEnd

    fn create(_: Self::Properties, mut link: ComponentLink<Self>) -> Self {

        let location = window().location().unwrap();
        let path = location.href().unwrap();

        let mut target = Some(RouterTarget::Index);
        if path.contains("about") {
            target=Some(RouterTarget::About);
        }

        Self {
            route_target: target,
            router_agent: RouteAgent::bridge(link.send_back(Message::Route)),
        }
    }

with this handling... either #about or \about\ or \about would be able to route to RouterTarget::About

@hgzimmerman
Copy link
Member Author

There is a little more nuance to handling this sort of redirection in warp, take a look at the example here to see how this pattern can support serving requests from /api/ in addition to the static assets without having to enumerate every possible frontend path.

@jstarry jstarry transferred this issue from yewstack/yew_router Apr 20, 2020
@jstarry jstarry added A-examples Area: The examples A-yew-router Area: The yew-router crate labels Apr 20, 2020
@siku2
Copy link
Member

siku2 commented Oct 8, 2020

Closing this because Trunk now provides this feature during development. In #1559 we merged the router examples with the main set and ended up removing the server templates.
For production environments, I think it's reasonable to expect users to be able to configure their server framework for SPAs. An ever growing list of server templates sounds like a nightmare to maintain and keep up to date.

@siku2 siku2 closed this as completed Oct 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-examples Area: The examples A-yew-router Area: The yew-router crate
Projects
None yet
Development

No branches or pull requests

4 participants