-
Notifications
You must be signed in to change notification settings - Fork 680
Fix 404 - when url entered directly into the browser #92
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
Conversation
Pull Request Test Coverage Report for Build 497
💛 - Coveralls |
|
||
// Forwards all routes to FrontEnd except: '/', '/index.html', '/api', '/api/**' | ||
// Required because of 'mode: history' usage in frontend routing, see README for further details | ||
@RequestMapping(value = "{_:^(?!index\\.html|api).*$}") |
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.
The forward
in this rule did not work for two reasons
- it was placed int he wrong
RequestMapping
context as it would look for the pattern only after/api
- it was placed in a
RestController
instead of aController
that does not support returning aforwad:/
Although the filter probably does work the easier solution would be to just fix 1) & 2)
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.
Thanks for the info, I didn't knew about it! I'll see if it works and I'll update the PR in the mean time
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.
@hemeroc I've tried to follow your idea, you were right about the using Controller instead of RestController but unfortunately, this solution only works on one level URLs like this /login
but not for this /auth/login
or any URL that has many deep level path as you can see the tests here:
spring-boot-vuejs/backend/src/test/java/de/jonashackt/springbootvuejs/SpaRedirectTest.java
Lines 34 to 41 in 86785f7
void redirectSpa() { | |
ValidatableResponse response = RestAssured.when().get("/path").then(); | |
assertSpaResponse(response); | |
response = RestAssured.when().get("/nested/path").then(); | |
assertSpaResponse(response); | |
response = RestAssured.when().get("/deep/nested/path/with/many/may/deep").then(); | |
assertSpaResponse(response); | |
} |
Do you have any idea on how to match URLs with multiple levels?
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've found a way to accomplish using @Controller
instead of Filter
I'll update as soon as possible
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've found a way to accomplish using
@Controller
instead ofFilter
I'll update as soon as possible
when you will update :)
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.
@isneezy great contribution 👍 Sorry, didn't find the time earlier.
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.
Think that's great, I'll resolve the JUnit 4 issue that will occur, since there's no RunWith
anymore in Spring Boot 2.4.x. Thanks again 👍
|
||
// Forwards all routes to FrontEnd except: '/', '/index.html', '/api', '/api/**' | ||
// Required because of 'mode: history' usage in frontend routing, see README for further details | ||
@RequestMapping(value = "{_:^(?!index\\.html|api).*$}") |
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.
@isneezy great contribution 👍 Sorry, didn't find the time earlier.
…ixed SpaRedirectTest not Found message String.
…tSpa:33->assertSpaResponse:58 1 expectation failed. Response body doesn't match expectation. Expected: a string containing "<script src=/static/js/chunk-vendors" Actual: <!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1"><link rel="icon" href="/favicon.ico"><title>frontend</title><link href="/static/css/app.6dd46426.css" rel="preload" as="style"><link href="/static/css/chunk-vendors.2f24a82e.css" rel="preload" as="style"><link href="/static/js/app.5c8c692c.js" rel="preload" as="script"><link href="/static/js/chunk-vendors.f6c6f821.js" rel="preload" as="script"><link href="/static/css/chunk-vendors.2f24a82e.css" rel="stylesheet"><link href="/static/css/app.6dd46426.css" rel="stylesheet"></head><body><noscript><strong>We're sorry but frontend doesn't work properly without JavaScript enabled. Please enable it to continue.</strong></noscript><div id="app"></div><script src="/static/js/chunk-vendors.f6c6f821.js"></script><script src="/static/js/app.5c8c692c.js"></script></body></html>`
I've fixed the White Label error with a simple filter by reusing the existing REGEX
The only catch up with this approach is that if you plan to have other URLs other than
/api
ex:/oauth
etc you'll have to include them in the REGEX expressionFixes #41