Spring Boot not serving Vite dist/prod build assets, only index.html - java

I have a Java Spring Boot backend, with a Tomcat server configured.
I have a React frontend, packaged using Vite, with "vite build" sending everything to a "dist" directory.
I move this "dist" directory to my "src/main/resources/static/" directory to be served automatically by Spring. This is running in a Docker container.
I'm able to pull up my home page. However, the front-end isn't picking up any CSS packaged by Vite, despite the fact I can see it in the dist folder under dist/assets/*, and the path in my dist/index.html to that assets/index-${HASH}.css file is correct.
This is only happening on sub-routes from index.html in my app. It's worth noting that when I refresh the page, I get a "Whitelabel Error Page". It's like my app doesn't recognize that, for example, https://localhost/route/routetwo is supposed to be a persistent path from the entrypoint index.html.
What's weird about this, and making it hard to troubleshoot, is that everything works correctly when running vite preview in a different Docker container. I'm able to see the child routes with the correct CSS, refreshing the page with no issue, etc.
In "Developer Tools -> Sources" I see the contents of index.html for the sub-route when running vite preview, but not when trying to serve it as part of Spring. It's something about how Spring is interacting with my vite build.
Any ideas?
I've tried numerous things, including but not limited to:
Pulling the dist out of the vite preview container, pasting it into my backend src/main/resources/static directory and serving it that way rather than building dynamically with each Docker container. No dice, still not finding my /assets/index-${HASH}.css
Doing the same as the above, but moving assets/* out of the assets directory and into the same directory as src/main/resources/static/index.html, changing the pathing in index.html. No result.
Considerable testing to make sure it's not a directory issue with my Docker builds. Confirmed there's basically no difference between the successful container and the unsuccessful except one is using vite preview and the other is using Spring static asset serving.

Related

Jhipster with production profile

I have built my jhipster application in production version(frontend app), it did minify all the javascript files and html files, I can see that inside the war, and I run the application in production version too as after completely starting it says jhipster started and the profile has swagger, prod. But when I access my application there is little source folder that gets created and that exposes all of my javascript code as javascript is not minified, over there.
what is this folder?
Why does this folder exists?
how do I disable this folder?
Link to the screenshot
You should probably disable source maps in gulp/build.js also gulp-uglify uses default options which you may want to change.

Avoid refreshing html pages in eclipse for spring boot app

I'm using Spring Boot to deploy a webbased app (services on the backend, SPA app for the front end).
I'm not using Eclipse to edit my html-related files.
If I put those files under "resources", when using Eclipse to debug the app, any changes (to the html-related files) made using the other editor is not picked up by the "embedded" tomcat, unless I refresh the file in Eclipse too.
Everything works great if I put the html-related files in webapp/: I don't have to refresh the files in Eclipse; but then the files are not picked up by the jar maven build (because spring boot jar is not supposed to pick them by design...)
How do you usually work with html-resources?
I don't want to use Eclipse to edit my html-related files, and I don't want to use nodejs/other proxy-style server tool (I have a capable webserver called "tomcat", I don't see the need to have yet another tool to install/configure/update etc)

Wildfly deploys non-war extension files without any error, but accessing the application in the browser gives a 404 Page Not Found

I'm learning web application development and deployment, using NetBeans and Wildfly 8.2.0. I was curious as to how a web application is deployed, and decided to play around to satisfy my curiosity.
I created a demo eCommerce JSF app with an eCommerce.war file, and deployed it using Wildfly's admin panel. It worked without any errors. Then, I changed the name & extension of eCommerce.war to testCommerce.abc and tried deploying it. And although not a .war extension, or .jar or .ear for that matter, it deployed succesfully, but I got a 404 when I tried to access it in the browser. I disabled the eCommerce.war app from the Admin Panel, and tried to access testCommerce.abc, but still got a 404.
Can anyone explain why Wildfly does not check file extensions before deployment? Is it because it expects an archive file and/or the file extension does not matter? And why, when deployment has been successful, I get a 404 in the browser for the .abc application? Is it due to changes coming in the directory paths when .war is changed to .abc? I've posted the Deployments section's image from the Admin Panel for verification.

JSP changes not reflecting when server is run. (JBoss, Maven, Eclipse)

I don't think the issue is isolated solely to my JSPs. However, the current files I'm trying to edit are JSPs.
Whenever I make changes to my JSP, I save the file (in Eclipse), clean/republish my JBoss server, start the server, and access the application (localhost), yet the changes I made are not reflected on the page at all.
I go to the JBoss temp directory to see exactly what version of the file (that I'm editing) the server is currently using. I always see that it's using the original version that I pulled down from the original repo. I have no idea why it's not changing.
I tried re-cloning and re-importing everything just out of desperation, and I'm getting the same results.
In addition, strangely, when I run the command mvn -U clean package -DskipTests=true to do a command-line build using Maven, my file reverts back to the original/unchanged version. (New to Maven, so it's strange to me at least).
So, essentially any changes I am making to files for my project aren't being reflected on my local test server. I'm totally stumped as to why it's behaving like this.
You can put JBoss in development mode. This is a mode in which JSPs are always re-compiled. Thus when you deploy a JSP change, you can immediately see it.
For JBoss 7, edit the file: /jboss/{server_name}/configuration/standalone.xml. Locate the "jsp-configuration" element and set the "development" attribute to true.
<configuration>
<jsp-configuration development="true" x-powered-by="false"/>
</configuration>
Note:
This file is in a different location in different versions of JBoss.
{server_name} in the path above will be specific to your JBoss install. If you have not created a server, then this value is likely "default" for you. You can easily find this value by looking at where your web app is deployed.
It is a good idea to deploy your web application in "exploded" format. That is, rather than deploying it as a WAR file (which takes time to build), explode (i.e. unzip) the contents of the web app right in the JBoss deployment area. That way when you need to make a JSP change, you simply copy the one JSP file.

Website directory structure different from eclipse

I am coding a website using java servlets and am using eclipse and tomcat. When I test it using localhost, it works fine. But when I am deploying it on my actual website, the directory structure is messed up and the files are not called properly.
My eclipse directory structure on localhost is
Project Name
.src/packageName/java files
.WebContent/HTML files.
When I make a call from the html files, I use the relative location and tomcat automatically knows to look in the src/packageName folder. For example, from the /WebContent/login.html page makes a onClick call as follows,
. This will automatically trigger the java file in /src/packageName/welcome
When I am deploying it in my actual website, the WebContent/login.html is throwing an error WebContent/welcome file is not found. How do I tell my website to search in /src/packageName folder?
Hmm...have you been sure to package the application as a war for deployment.

Categories

Resources