Skip to content
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

Spring Setup and Mime type issue #10017

Open
dgeiselmanMOO opened this issue Oct 22, 2024 · 10 comments
Open

Spring Setup and Mime type issue #10017

dgeiselmanMOO opened this issue Oct 22, 2024 · 10 comments

Comments

@dgeiselmanMOO
Copy link

GWT version: 2.11
Browser (with version): Chrome 129.0.6668.101
Operating System: Windows 11


Description

I'm working on moving our GWT applications to cloud servers and having them run with Springboot. When I try to run with Spring and load the page it is giving me the error

Refused to execute script from 'http://127.0.0.1:8888/healthunderwritingdashboard/healthunderwritingdashboard.nocache.js' because its MIME type ('application/json') is not executable, and strict MIME type checking is enabled.

The nocache file is definitely not a json file but it seems it is being detected as one. What can be done to fix the content type of the nocache.js file so it isn't coming up as json but as javascript as it should be.

Steps to reproduce

Running a GWT application with Springboot

Known workarounds
Links to further discussions
@niloc132
Copy link
Contributor

It sounds like this might be a better question for a Spring Boot forum? GWT doesn't provide any file-serving code for other server implementations, and I don't think you're reporting this issue for the Dev Mode server (implemented with Jetty)?

@dgeiselmanMOO
Copy link
Author

Is there any good information on getting GWT and Spring to interact?

@jnehlmeier
Copy link
Member

Have you checked the contents of the nocache.js file in browser dev tools / network tab? Maybe it contains a JSON formatted error produced by spring boot and thus spring boot uses JSON MIME type.

If the browser really receives JS content in the nocache.js file, then you should probably ask the springboot people why springboot provides a wrong mime type for JS files.

@dgeiselmanMOO
Copy link
Author

Or maybe I need to figure out why it is saying the file doesn't exist.

@FrankHossfeld
Copy link
Member

FrankHossfeld commented Oct 22, 2024

Thie maven archetype generates a working GWT + Spring Boot project: https://github.com/NaluKit/gwt-maven-springboot-archetype. Based on this archetype, I have several projects using Spring Boot and never ran into this error. May be you can generate a project using this archetype creator and check if this one is working.

BTW, are you working with Windows? If yes, you might check this:
https://stackoverflow.com/questions/40574159/refused-to-execute-script-strict-mime-type-checking-is-enabled

@dgeiselmanMOO
Copy link
Author

The reason is that the folder with the nocache.js is not being found which is leading to the nocache.js itself not being found. When running from IntelliJ it isn't looking at my war file. Have to look at some configurations and then figure out why Docker is not finding my main class

@FrankHossfeld
Copy link
Member

FrankHossfeld commented Oct 22, 2024

Without knowing your set up, it is hard to say what's going wrong. Using GWT with Spring Boot is a little bit tricky. You need to add the launcherDir to the Spring Boot class path. Something like that in the application.yaml should do the job:

  web:
    resources:
      static-locations: classpath:/launcherDir/,classpath:/public/

But without seeing your project, it is hard to help. Just generate a project using the maven archetype builder and check the set up. Also, keep in mind, before starting Spring Boot, the code server must be running. Otherwise, the launcherDir is not created. So, wait until you see the code server url in the terminal window before starting the Spring Boot server.

@niloc132
Copy link
Contributor

If the file isn't being found, I'm not sure why you would get a json mime type back - unless maybe there is a servlet preventing loading any files from the filesystem (or the war), and is treating every call as a "rest" (or other json-over-http) call, just to a service/type that doesn't exist?

@dgeiselmanMOO
Copy link
Author

How should the jar be setup for GWT with Spring? We use gradle to build. I can get things to build, but I don't think the files are in the right places.

@niloc132
Copy link
Contributor

Without seeing the rest of your build or code, it is hard to make concrete suggestions - Gradle, with or without plugins, is extremely flexible, as you can run any code as part of the build process, so nearly anything could be produced as part of that build.

Instead of approaching it from this angle, I'd suggest you start with these questions to take a closer look at what is happening:

  • What is the actual response from the server when you try to load the .nocache.js file? Do you see JSON contents, or the expected JS file? You can test this either by checking the network tab of your browser's dev tools, or directly navigating to the URL you expect to work
  • What change did you make that caused this to start happening? From your initial question you said "moving our GWT applications to cloud servers and having them run with Springboot" - how much of that process is done, and exactly what changed? After which change were the files no longer able to be served?
  • How is the host html file served, and where is it located on disk (in a jar/war/etc)? Before the project broke, was it located in the same place? Before the project broke, where was the compiled JS?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants