Invalid Static JS Content Type on Google AppEngine Standard Environment

385 views
Skip to first unread message

Ali Koc

unread,
Dec 6, 2018, 9:54:49 AM12/6/18
to Google App Engine

I have a simple java application running on Google App Engine Standard environment, which along with servlets, also contains static html, css and js files.


It seems js files are always served with "content-type: text/plain". Even when I create a new Hello App Engine application (doing this in Eclipse through GCP plugin) and add a simple js file to the project and deploy. The js file is served as content-type: text/plain.


Note that when I debug locally, the files is served as application/javascript as expected. The issue only occurs on the deployed version.


Here is the link to the file in the hello world application:

https://test2-dot-baruch-221323.appspot.com/test.js


This is using Java 8. Here is what web.xml file look like:


<?xml version="1.0" encoding="utf-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee 
         http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
         version="3.1">
  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>
  <mime-mapping>
    <extension>js</extension>
    <mime-type>application/javascript</mime-type>
  </mime-mapping>
</web-app>


What am I missing here? Other static files such as html and css come with correct content type, js seems to be the only one with issue. Can you give me some pointers on how to debug this?

George (Cloud Platform Support)

unread,
Dec 6, 2018, 8:58:50 PM12/6/18
to Google App Engine
Hello Ali, 

You seem to want to deploy a Java app. If this is the case, you must put your static served files within your app's webapp directory. After you choose a location for the static files, you must define their location in the appengine-web.xml file, using the <static-files> element. More detail can be gathered from the "Getting Started: Serving Static Content" documentation page. [1]

App Engine can serve static content such as HTML pages and media such as images. Static content is anything that will not be executed as JSPs or Servlets. 

How do you deploy your app? Is it with gcloud app deploy, Maven, or Gradle? A procedural description, in step-by-step fashion, would be appreciated. 

Ali Koc

unread,
Dec 7, 2018, 9:03:31 AM12/7/18
to Google App Engine
Hello, George!

1- Sure all static files are in webapp folder. (see attached zip file) All I am doing is creating a new Java Standard environment hello world app.  

2- I didn't know using <static-files> element to define static files was a must. I was going with this documentation which says it is optional and in fact works without it as long as the static file is inside webapp folder (public-root). But I added the static files section with no help. 

appengine-web.xml:

<?xml version="1.0" encoding="utf-8"?>
<appengine-web-app xmlns="http://appengine.google.com/ns/1.0">

  <threadsafe>true</threadsafe>
  <sessions-enabled>false</sessions-enabled>
  <runtime>java8</runtime>

  <system-properties>
    <property name="java.util.logging.config.file" value="WEB-INF/logging.properties"/>
  </system-properties>

  <static-files>
    <include path="/**.js" >
    </include>
  </static-files>
  
</appengine-web-app>

web.xml

<?xml version="1.0" encoding="utf-8"?>
         version="3.1">
  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>
  <mime-mapping>
  <extension>js</extension>
  <mime-type>application/javascript</mime-type>
  </mime-mapping>
</web-app>

the js file is still served as text/plain. you can check it on this link:


The whole hello world project is added for your reference (attached zip file). I deploy from within Eclipse using Eclipse GCP plugin. See below screenshot. This was working fine before September 14 and it broke before September 7 and September 14 -- the version of the app that was deployed on September 7 has js files served as application/javascript where as starting September 14 version, the same files are served as text/plain. Between these dates, there has been no change to the build or deployment, just modifications to the contents of static files. But we regularly update the google cloud sdk on the deployment machine. So I suspect this is a bug introduced in one of the sdks. 

screenshot.png




- ali

George (Cloud Platform Support)

unread,
Dec 7, 2018, 5:18:29 PM12/7/18
to Google App Engine
Hi Ali, 

You mention Eclipse GCP plugin. Do you actually use the proper Eclipse GCP Plugin? Do you refer to the Tools for Eclipse? If you still use the unsupported GCP Plugin, it is advisable to migrate to the Tools, as indicated in the "Migrating from the Google Plugin for Eclipse" online document. Results may differ if you deploy through approved channels. If the error still persists, we'll investigate further. 

Ali Koc

unread,
Dec 8, 2018, 2:09:32 PM12/8/18
to Google App Engine
I am using the Google Cloud Tools for Eclipse -- which technically still accessed through Eclipse plugin but I know what you mean -- there should really be better naming for these.

For your reference, see below screenshot:

eclipse.png


At your end, are you able to:
- download latest eclipse, 
- install Google Cloud Tools for Eclipse, 
- create hello world application (add a dummy js file)
- deploy to app engine standard environment.  

Do you js files being served as text/plain or application/javascript?

- Ali

Mohammad I (Cloud Platform Support)

unread,
Dec 10, 2018, 10:13:35 PM12/10/18
to Google App Engine

Hello Ali,


Please kindly note that this forum is meant for general discussion of the App Engine platform, not specific technical issues. If you believe that what you've encountered is platform specific issue you can report this by creating an issue in the Issue Tracker and Google Cloud Support team member will assist you to resolve your issue.  If your issue is not a platform issue but rather a problem with how you've configured your code, although you're not sure what it may be specifically, you should post to StackOverflow and community of developers will assist you.


In addition, I have noticed your project_id in this Google Group thread. I would advise you to take caution before sharing any personal project specific information like these in any public forums as they can be used to harm your application.


Reply all
Reply to author
Forward
0 new messages