You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When redirecting to an error page in my Spring Boot application running on GitHub Codespaces, an incorrect port (8080) is being added to the URL. This causes the redirection to fail.
Current Behavior
The application is accessible via https://[CODESPACE-NAME]-8080.app.github.dev/
When attempting to redirect to the error page, the resulting URL becomes https://[CODESPACE-NAME]-8080.app.github.dev:8080/error-page
This URL with the added :8080 doesn't work in the Codespaces environment.
Expected Behavior
The redirect should maintain the correct URL structure without adding the extra port: https://[CODESPACE-NAME]-8080.app.github.dev/error-page
Code Snippet
@GetMapping("/cart")
public String getCart(HttpSession session, Model model, RedirectAttributes redirectAttributes) {
// ... (other code)
if (response.getStatusCode() != 200) {
String baseUrl = UriComponentsBuilder.fromHttpUrl(request.getRequestURL().toString())
.replacePath(request.getContextPath())
.build()
.toUriString();
System.out.println(baseUrl);
redirectAttributes.addFlashAttribute("statusCode", response.getStatusCode());
redirectAttributes.addFlashAttribute("message", response.getMessage());
return "redirect:" + baseUrl + "/error-page";
}
// ... (rest of the method)
}
Attempted Solutions
Initially tried "redirect:/error-page", but it didn't work.
Implemented the UriComponentsBuilder solution as shown in the code snippet, but the issue persists.
Questions
How can I generate the correct redirect URL that works in the GitHub Codespaces environment?
Is there a way to detect if it's running in Codespaces and adjust the URL generation accordingly?
Are there any Spring Boot or Codespaces-specific configurations I might be missing?
Additional Context
The error page itself (/error-page) is defined as follows:
CodespacesYour development environment, in the cloud. Run VS Code and code on GitHub's cloud platform,Question
2 participants
Heading
Bold
Italic
Quote
Code
Link
Numbered list
Unordered list
Task list
Attach files
Mention
Reference
Menu
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Select Topic Area
Question
Body
Environment
Description
When redirecting to an error page in my Spring Boot application running on GitHub Codespaces, an incorrect port (8080) is being added to the URL. This causes the redirection to fail.
Current Behavior
https://[CODESPACE-NAME]-8080.app.github.dev/
https://[CODESPACE-NAME]-8080.app.github.dev:8080/error-page
Expected Behavior
The redirect should maintain the correct URL structure without adding the extra port:
https://[CODESPACE-NAME]-8080.app.github.dev/error-page
Code Snippet
Attempted Solutions
"redirect:/error-page"
, but it didn't work.UriComponentsBuilder
solution as shown in the code snippet, but the issue persists.Questions
Additional Context
The error page itself (/error-page) is defined as follows:
Any help or guidance on resolving this redirection issue in the Codespaces environment would be greatly appreciated.
Beta Was this translation helpful? Give feedback.
All reactions