Spring boot also serve content from sub directory index.html - spring-boot

I have a spring boot server that serves content from the public/ directory inside resources. When I do GET / I get the content of the index.html.
But I also have a subfolder inside public, let's call it foo, with another index.html. However when I do GET /foo I get 404, I need to access the index.html specifically. How can I make it return index.html for the subpath, without specifying it in the url?

Related

Website showing 404 instead of automatically showing index.html

I use OpenLiteSpeed as a web server, and when I load my website I get a 404 error instead of it automatically loading the index.html page, when I put index.html in manually the page loads without a problem

Laravel ISPConfig/Nginx directives

I have a laravel app and my client needs to access it via subfolder (let's say clientdomain.com/laravelapp/). I have already moved the contents of laravel's /public/ folder to /laravelapp and setup the index.php file so it references the right path.
I ended up with the following structure:
- /public_html (webroot of the server)
- /myapp/ (this is the public folder that was inside the laravel project)
- /laravel-framework (this is the laravel project folder with controllers, views, vendors, etc)
It works ok when I access the main route (clientdomain.com/laravelapp), it shows views, images and everything ok. The problem is when I try to access a different route, it shows 404.
I can't manually setup the nginx conf file, but ISPConfig has a box for nginx directives.
What are the right directives for a setup like mine?
I thank you in advance.
Try to add this to box for nginx directives.
location / {
try_files $uri $uri/ /index.php?$args;
}

Spring MVC resources not being mapped

my folder structure
enter image description here
And my code in the JSP page is
<script src='${pageContext.request.contextPath}/AppNameController.js'/>
I'm still getting 404 error
You have the prefix set to /WEB-INF/jsp but looking at your project structure your index.jsp is only within the /WEB-INF folder rather than inside the /WEB-INF/jsp folder.
Also change to:
${pageContext.request.contextPath}/resources/scripts/AppNameController.js

IF request mapping unresolved AND path not found in static resources location then redirect to index.html

The problem (caused by frontend, angularjs context):
"X uses HTML5 mode in its location service. It means, you will see URLs like www.example.com/mail rather than seeing URLs like this one: www.example.com/#/mail
Also, without following .htaccess rules, you can't access your application directly. So typing www.example.com/mail to the url bar or refreshing your application will cause an Internal Server Error.
Create an .htaccess that stays with the same directory as your index.html and paste the following code inside it:"
<IfModule mod_rewrite.c>
RewriteEngine On
# Send all requests to the index.html unless
# it's a directory or a file that actually exists
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.html [L]
</IfModule>
As I am using tomcat this script is as as useful as pseudo code which must be put in Spring Boot application. Otherwise none of the directly typed paths within browser work(get 404 white label server page).
Effectively I need to implement something similar. I can't even figure out which components I should even look at.
So far disjointed pieces of info in my brain:
Spring filters from filter chain and resources handlers are hit in the order I mentioned them (according to trace logs).
I need to redirect to index.html whenever the path is:
A. Not a rest api controller path AND
B. Not resolved to a static resource within(in my case: 'static' resource folder).
So do I need to create custom resource handler/custom filter? Or maybe problem lies in different dimensions? (tomcat itself?)
The problem was more logical than technical:
A. The paths which must resolved by angular js have nothing to do with backed
-> meaning, that backend has no knowledge which paths angular is aware of and which are not.
B. Therefore, if a resource is not resolved by the controllers and resource handlers - this is 404 case for backend. So:
#Component
public class WebConfiguration implements EmbeddedServletContainerCustomizer {
#Override
public void customize(ConfigurableEmbeddedServletContainer configurableEmbeddedServletContainer) {
configurableEmbeddedServletContainer.addErrorPages(new ErrorPage(HttpStatus.NOT_FOUND, "/index.html"));
}
}
Resolves the issue. The outcome is that whenever we go to /mail, backend returns index.html , then angular resolves the internal path and displays email partial. How angular does it I am not sure myself, I don't know how the html5 model remembers the path.
The shortage of this solution is that request to rest api, targeting wrong rest api path will receive index.html, but status is set so should be no big deal.
It would nice however to know at which point within the backend flow it is known that the request did not resolve neither to controller neither to static resource and how to capture this behavior.

LARAVEL Sub Domain Routing Not Executed

Hi there i have some stupid mistake in configuring laravel.
First of all, this is my structure of folder
i use shared-hosting service and i place my laravel app, vendor and bootstrap into lib folder outside the htdocs (public/public_html) folder
so basically:
var
public_html
www
lib
-app
-bootstrap
-vendor
i create two subdomain called console for client and panel for admin
so i could call the subdomain specific url to access the system
this two subdomain is placed inside the public_html
public_html
-console
-panel
Then i move the public folder from laravel original into console folder (subdomain) with all the content from public folder (index.php, .htaccess, etc.)
Console.myDomain.com is working perfectly.
Now i want to create the admin system from the panel.myDomain.com i have created the subdomain and place all assets files (css, js, etc.) and change the routes into:
Route::group(array('domain' => 'panel.myDomain.com'), function(){
Route::get('/', function()
{
return View::make('admin.index');
});
});
but the page only showing blank page, (the blank page is shown because i place index.php file without content inside the panel folder)
additional info i have setup the bootstrap/paths.php into 'public' => __DIR__.'/../../public_html/console'
and is it require to change?
what proper way to make the panel.myDomain.com execute the routes and showing the right blade i have made?
thank you.

Resources