-
Notifications
You must be signed in to change notification settings - Fork 79
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
Return content of /index.html instead of 404 #117
Conversation
Thanks for the PR! Hmm... I think it would be better to make this a little more configurable. Say, instead of this: index-on-404 = true something like this would be more elegant and flexible: 404-path = "/index.html" Also, in + let mut artifact = last_build.deployment.get_by_url( &path );
+ if artifact.is_none() {
+ if let Some( not_found_path ) = project.404_path() {
+ artifact = last_build.deployment.get_by_url( ¬_found_path )
+ }
+ }
+ if let Some( mut artifact ) = artifact {
- if let Some( mut artifact ) = last_build.deployment.get_by_url(&path) { |
Thanks for the feedback! |
I've made the requested changes. Lets assume that I attempt to do the following with Successful load
Failed load
So it can be seen that this PR allows the app to start from any 1-path-segment route, but any more segments breaks the way the browser loads subsequent resources with the current setup. This is the html returned when <!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=1" name="viewport" />
<script>
var Module = {};
var __cargo_web = {};
Object.defineProperty( Module, 'canvas', {
get: function() {
if( __cargo_web.canvas ) {
return __cargo_web.canvas;
}
var canvas = document.createElement( 'canvas' );
document.querySelector( 'body' ).appendChild( canvas );
__cargo_web.canvas = canvas;
return canvas;
}
});
</script>
</head>
<body>
<script src="my_app.js"></script>
</body>
</html> I think this problem can be fixed by changing this line to make the browser fetch it from an absolute location: <body>
<script src="/my_app.js"></script> <!-- Absolute path now -->
</body> |
Sounds good to me! |
src/cmd_start.rs
Outdated
let mut artifact = last_build.deployment.get_by_url( &path ); | ||
if artifact.is_none() { | ||
if let Some( ref not_found_path ) = path_404 { | ||
println!("Artifact could not be found, but should try to get user specified path instead"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Having this print here is probably unnecessary (it'll just spam the console); you can put a debug!
log instead, e.g.:
debug!( "{} not found; serving {} instead", path, path_404 );
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, that was there as an accident. I had it there as a quick printf-debuging thing and removed it but didn't save before I committed. (I switched back from Clion to VS Code, and forgot that autosave was disabled when I made the commit).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still a good idea to add the debug though.
@@ -19,13 +19,13 @@ if( typeof Rust === "undefined" ) { | |||
if( typeof window === "undefined" && typeof process === "object" ) { | |||
var fs = require( "fs" ); | |||
var path = require( "path" ); | |||
var wasm_path = path.join( __dirname, "{{{wasm_filename}}}" ); | |||
var wasm_path = path.join( __dirname, "/{{{wasm_filename}}}" ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I haven't tested the additional /
here, but I assume that the path.join()
function would produce the same output regardless of the /
being there or not.
Let me know if you would like me to remove this change.
I think aside from the small question above, this should be ready for another review. |
@hgzimmerman Sorry for the delay! Looks good to me, thanks a lot! 👍 I'll merge it in once we get the latest nightly stabilized. |
Any update on this? |
@jiegec I haven't got around to it yet. The extra slash added to the runtimes here is actually a backwards incompatible change, which is why I haven't merged this yet. Once I finish getting |
@koute are there any remaining blockers before this can be merged? |
I'm around for the near future if you want me to get this in a mergable state again. |
@koute will be nice to merge this feature. Now I have to execute 4 commands with cargo watch and build my own rendering server to run my project when with this PR only I would need to use cargo web. @hgzimmerman told you that he can get this in a mergable state. |
With the time passed since this was started, I no longer plan to get this feature merged. Someone else is welcome to take up the mantle if they so choose. |
The PR that implements the feature request detailed in #100.
I don't think it is exactly clean enough to merge in its current state, but I have tested it and observed that it worked as intended, returning the index.html file instead of a 404 response when a requested file path doesn't exist.
This would allow a yew application with routing to return to a routed page when a page refresh is performed, improving developer ergonomics.