-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
static web page router question #723
Comments
You may want to give us a small example. It is quite hard to understand your problem without any bit of code showing what exactly you want to archive |
I think the issue he's having is that requests to a folder don't open index.html. This is standard default behavior for servers serving static assets like nginx and apache and some async web frameworks have static file serving with that behavior available built in. You can see the lack of this feature in the example code in the guide. I'll probably have some code to share for this soon. |
If |
ah, i misunderstood the issue then it would just be #[get("/<_file..>")]
fn files(_file: PathBuf) -> Option<NamedFile> {
NamedFile::open(Path::new("static/index.html")).ok()
} Edit: except there are other static assets? #[get("/<file..>", rank = 10)] // set the rank higher than other endpoints
fn files(file: PathBuf) -> Option<NamedFile> {
NamedFile::open(Path::new("static/").join(file)).ok().or_else(|| NamedFile::open(Path::new("static/index.html")).ok())
} this will be annoying if you put in a path wrong, not sure off the top of my head how check that |
I think this is #239? |
@SergioBenitez: It's more than what appears planned with #239, but #239 could be extended to support it. |
Rocket version : 0.3.15
When I use react and react-router to build a web page and use rocket static file router,
I found the main page "/index.html" can work but router function can't work, get 404 back, and log shows my router "/answers" match "/<file..>", then 404,
I've tried to use redirect but not useful.
The text was updated successfully, but these errors were encountered: