0

I have a JHipster monolith application based on Angular 5. I am not able to replicate the configuration that I did to webpack through the webpack.dev.js file to the undertow when I compile and run under production profile.

Here are the important lines of my webpack.dev.js file:

module.exports = webpackMerge(commonConfig({ env: ENV }), {
    devtool: 'eval-source-map',
    devServer: {
        contentBase: './target/www',
        historyApiFallback: {
            index: '/MyApp/'
        },
        publicPath: "/MyApp/",

I have changed the Location strategy to a Custom one because I wanted to support both the HashLocationStrategy and the PathLocationStrategy at the same time. Plus I need the urls to be bookmarkable. Basically emulate the paths of an MVC and old angular applicaiton that is why I do this.

providers: [
    { provide: APP_BASE_HREF, useValue: '/MyApp' },
    { provide: LocationStrategy, useClass: CustomLocationStrategy },

and the custom location strategy:

import { Injectable } from '@angular/core';
import { HashLocationStrategy } from '@angular/common';

@Injectable()
export class CustomLocationStrategy extends HashLocationStrategy {
    prepareExternalUrl(internal: string): string {
        let url = this.getBaseHref() + '/#' + internal;
        if (internal === '/login') {
            url = this.getBaseHref() + internal;
        }
        return url;
    }
}

Now everything works ok under the development profile. For example the http://localhost:8080/ redirects me correctly to the http://localhost:8080/MyApp/login and if I reload the http://localhost:8080/MyApp/login I land at the same page (no 404). So these are bookmarkable as well.

But under production profile there are no proxy, history api fallback and publicPath variables.

Thus when I hit the http://localhost:8080 I receive a 404. When I hit the localhost:8080/MyApp works ok. When I hit the http://localhost:8060/MyApp/login I receive the:

A parser-blocking, cross site (i.e. different eTLD+1) script, https://linkhelp.clients.google.com/tbproxy/lh/wm?sourceid=wm&url=http%3A%2F%2Flocalhost%3A8060%2FMyApp%2Flogin&hl=en&site=localhost%3A8060&error=http404&js=true, is invoked via document.write. The network request for this script MAY be blocked by the browser in this or a future page load due to poor network connectivity. If blocked in this page load, it will be confirmed in a subsequent console message. See https://www.chromestatus.com/feature/5718547946799104 for more details.

and here is a screenshot: enter image description here

Thus the links are not bookmarkable. In production I am using NgInx as a reverse proxy. Could I somehow use this in order to emulate webpack/NodeJs ? I haven't managed yet unfortunately. Or it is possible to do the same with the tools that I already have (undertow, webpack under the prod profile?

Any suggestions how to solve this situation would be greatly appreciated.

UPDATE 2.1: I have followed your comments Gael. I have included the filter with some additional patterns and indeed all requests give back now a 200 - OK response. When I hit the http://localhost:8060/MyApp/login all the requests return 200 but at the console I see

Uncaught SyntaxError: Unexpected token <

here is a screenshot as well: enter image description here

I have returned the appropriate content type as well based on the extension of the file that I return:

  1. text/javascript for the js files
  2. text/css for the css files
  3. and text/html for all the rest

Do you have any pointers please?

Thank you!

Investigator
  • 1,431
  • 2
  • 17
  • 24
  • 1
    Have you configured a servlet filter to support deep linking with PathLocationStrategy? I have already answered this on SO and provided an example of filter. – Gaël Marziou Apr 20 '18 at 17:30
  • No I haven't done anything like that. I would appreciate if you could you please paste the link. – Investigator Apr 20 '18 at 18:43
  • 1
    See https://stackoverflow.com/questions/48567071/jhipster-refresh-url-cause-cannot-get-user-management and https://stackoverflow.com/questions/38516667/springboot-angular2-how-to-handle-html5-urls – Gaël Marziou Apr 20 '18 at 18:53
  • Hi @GaëlMarziou I removed the contextPath and I have added the filter that you said. I have also added a few more patterns. All of the resources now return 200 - OK, no 404 anymore. Now I face the following problem when I hit the localhost:8080/MyApp/login Refused to apply style from 'http://localhost:8080/MyApp/global.9a6d5bccf16e3b824fcb.css' because its MIME type ('text/html') is not a supported stylesheet MIME type, and strict MIME checking is enabled. the same for main.9a6d5bccf16e3b824fcb.css an then 5 messages like that: Refused to execute script from '...js' because its MIME t.. – Investigator Apr 21 '18 at 09:26
  • Refused to execute script from 'http://localhost:8080/MyApp/app/manifest.9a6d5bccf16e3b824fcb.bundle.js' because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled. I believe this is related to the CORS but I already have this enabled # CORS is only enabled by default with the "dev" profile, so jhipster.cors.allowed-origins=* jhipster.cors.allowed-methods=* jhipster.cors.allowed-headers=* jhipster.cors.exposed-headers=Authorization,Link,X-Total-Count jhipster.cors.allow-credentials=true jhipster.cors.max-age=1800 – Investigator Apr 21 '18 at 09:31
  • I believe this is related to removal of the contextPath as well. I did this in order to catch the root as well / – Investigator Apr 21 '18 at 09:34
  • 1
    You should edit your question if you want help because it's hard to follow in comments. – Gaël Marziou Apr 21 '18 at 09:50

0 Answers0