How to configure redirects Glassfish4 Maven Webapp - angularjs

I am developing a WebApp using Glassfish 4. I have a REST backend, developed in JAVA using Jersey, and a AngularJS frontend. All this is contained in a MAVEN Jersey-Quickstart-Webapp.
Now, the problem I have is that when people query the URL for my app:
http://localhost:8080/MyApp/
It works fine, and sends the appropriate index.html to the user. However, if the user types a URL that 'should' be handled by my Apps routing, say like:
http://localhost:8080/MyApp/search
it gives a 404 error. However, this URL can be reached from within in the app if you start from the /MyApp/ route, because the index.html that is served with all the angularJS stuff is able to understand and control the routing.
Essentially the problem I face is that I need to set up the appropriate redirects for all the necessary places that should return the index.html.
So, when I hit any of the following URLs it should send the user the index.html, and let AngularJs figure out the routing
Eg.
http://localhost:8080/MyApp/search ----> index.html
http://localhost:8080/MyApp/results ----> index.html
http://localhost:8080/MyApp/browse ----> index.html
Unfortunately, I am probably being really thick here, but I don't know how to configure the server/webapp to do this. How do I go about doing this? I assume it is fairly obvious/trivial, but I'm pretty new to all this stuff, so go easy on me!
EDIT 1: I've had some good help about using a mod-rewrite or the UrlRewriteFilter but neither of these seems to work for Glassfish4 as far as I can see. Is there an equivalent out there for these that somebody might know of?

Log into glassfish In the Admin Console, expand the Configurations
node. Expand the server-config node. Ignore this step if you are
running a developer domain (a domain that does not have clustering
capability). Expand HTTP Service. Expand Virtual Servers. Click
server. On the Edit Virtual Server page, click the Add Property
button. In the Name column, type redirect_1.
If you are using Application Server 9.0, type
from=//myproduct1
url-prefix=/mywarname/mypages/products/myproduct1.jsp in the Value
column.
Note - The value of the you provide here needs to
match the value of the context root specified in the web.xml or
application.xml file.

As #Tunaki says, you need use an apache and use the mod_rewrite.
also, you can use UrlRewriteFilter thats allows you to rewrite URLs before they get to your code.
For that, you need add to your maven file the dependency:
<dependency>
<groupId>org.tuckey</groupId>
<artifactId>urlrewritefilter</artifactId>
<version>4.0.3</version>
</dependency>
And add in your WEB-INF/web.xml file:
<filter>
<filter-name>UrlRewriteFilter</filter-name>
<filter-class>org.tuckey.web.filters.urlrewrite.UrlRewriteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>UrlRewriteFilter</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
</filter-mapping>
Also, you have a big number of parameters specified in the documentation:
http://cdn.rawgit.com/paultuckey/urlrewritefilter/master/src/doc/manual/4.0/index.html#filterparams
http://localhost:8080/MyApp/search ----> search.html
http://localhost:8080/MyApp/results ----> results.html
http://localhost:8080/MyApp/browse ----> browse.html

Related

Request denied based on content categorization: "Uncategorized URLs"

I have a reactJs SPA hosted on github pages with custom domain.
I indexed it in google search and also have description <meta> tags in my code.
All works fine on normal machine.
However, When I try to open the website behind a corporate firewall, I get this error
Request denied based on content categorization: "Uncategorized URLs"
I might never be able to open the site behind this firewall, because I can not update the firewall policies, but the reason mentioned in the blocking proxy is something I want to fix.
Question
My site is shown as "Uncategorized URLs".
As this is a SPA, and no content gets loaded until JS gets triggered so proxy might not be able to analyze the content, but is there a way to resolve this Uncategorized URLs issue by setting some <meta> tags or any quick fix except SSR

How to escape # character in HAProxy config?

I'm trying to modularize my front-end which is in Angular-JS, with it we are using HA-proxy as a load balancer and K8s.
Each ACL in the HA-proxy configuration is attached to a different service in K8s and since we are using Angular with the (hash-bang enabled), in the HA-proxy configuration file we use that as a way to identify the different modules.
Below is my configuration, in HA-proxy which is failing because I can't escape the # in the file even after following the HA Documentation.
acl login-frontend path_beg /\#/login
use_backend login-frontend if login-frontend
acl elc-frontend path_beg /\#/elc
use_backend elc-frontend if elc-frontend
I have tried escaping it as /%23/login and /'#'/admin but without success.
Any idea would be greatly appreciated.
The fragment (everything followed by a # character) as defined in RFC 3986
As with any URI, use of a fragment identifier component does not
imply that a retrieval action will take place. A URI with a fragment
identifier may be used to refer to the secondary resource without any
implication that the primary resource is accessible or will ever be
accessed.
and it is used on the client side, therefore a client (a browser, a curl, ...) does not send it with a request. As reference: Is the URL fragment identifier sent to the server?
So there is no point to route/acl with it. The reason why haproxy provide an escape sequence for that is you may want to include it with a body, a custom header... but again, you will not obtain that part from the request line (the first line with URI).
What is really happening here is the user is requesting from HAProxy / and Angular, in the user's browser, is then parsing the #/logic and #/elc part to decide what to do next.
I ran into a similar problem with my Ember app. For SEO purposes I split out my "marketing" pages and my "app" pages.
I then mounted my Ember application at /app and had HAProxy route requests to the backend that serviced my Ember app. A request for "anything else" (i.e. /contact-us) was routed to the backend that handled marketing pages.
/app/* -> server1 (Ember pages)
/ -> server2 (static marketing pages)
Since I had some urls floating around out there on the web that still pointed to things like /#/login but really they should now be /app/#/login what I had to do was edit the index.html page being served by my marketing backend and add Javascript to that page that parsed the url. If it detected a /#/login it forced a redirect to /app/#/login instead.
I hope that helps you figure out how to accomplish the same for your Angular app.

Using sw-precache with client-side URL routes for a single page app

How would one configure sw-precache to serve index.html for multiple dynamic routes?
This is for an Angular app that has index.html as the entry point. The current setup allows the app to be accessable offline only through /. So if a user go to /articles/list/popular as an entry point while offline they won't be able to browse it and would be given you're offline message. (although when online they'd be served the same index.html file on all requests as an entry point)
Can dynamicUrlToDependencies be used to do this? Or does this need to be handled by writing a separate SW script? Something like the following would do?
function serveIndexCacheFirst() {
var request = new Request(INDEX_URL);
return toolbox.cacheFirst(request);
}
toolbox.router.get(
'(/articles/list/.+)|(/profiles/.+)(other-patterns)',
serveIndexCacheFirst);
You can use sw-precache for this, without having to configure runtime caching via sw-toolbox or rolling your own solution.
The navigateFallback option allows you to specify a URL to be used as a "fallback" whenever you navigate to a URL that doesn't exist in the cache. It's the service worker equivalent to configuring a single entry point URL in your HTTP server, with a wildcard that routes all requests to that URL. This is obviously common with single-page apps.
There's also a navigateFallbackWhitelist option, which allows you to restrict the navigateFallback behavior to navigation requests that match one or more URL patterns. It's useful if you have a small set of known routes, and only want those to trigger the navigation fallback.
There's an example of those options in use as part of the app-shell-demo that's including with sw-precache.
In your specific setup, you might want:
{
navigateFallback: '/index.html',
// If you know that all valid client-side routes will begin with /articles
navigateFallbackWhitelist: [/^\/articles/],
// Additional options
}
Yes, I think you can use dynamicUrlToDependencies, as mentioned in the documentation of the directoryIndex option: https://github.com/GoogleChrome/sw-precache#directoryindex-string.

CakePHP Application: some pages with SSL, some without

I have an application written with the CakePHP framework and it is currently located in httpdocs. I want a few pages to be redirected to https://
Basically this shouldn't be a problem to detect whether the user is already on https://... or not. My issue is a different one: In my opinion I would need to make a copy of the whole project and store it in httpsdocs, right? This sounds so silly but how should it work without duplicating the code? I think I miss something but I don't get it ...
I have never had to copy the code for ssl. You should specify in the vhost for the site what the path is.
On apache there is a vhost for each, ssl and non ssl. Both can have the same webroot path.
If your webhoster requires you to put the https part of your website in httpsdocs, then you will need to put something there. But not the whole project: maybe only the /web part (the part that is actually served up by the webhoster).
Something like
/cake/app/ --> your app code
/httpsdoc/.. --> index.php and possibly css stuff, images etc
/httpsdocs/.. --> copy of index.php and the rest as well
Of course, you could also use some internal redirect in .htaccess
One suggestion: now that google indexes https urls, you could also choose to make the whole site available through https.

Why does my Azure application still point to default.aspx?

I have created a PivotViewer application with an Azure Web role, and it deploys on my local machine perfectly. When I deploy it to azure, the standard default.aspx "My ASP.NET" application is the loaded page. I can not seem to find a solution in all of the tutorials. If I point the browser to http://solution.cloudapp.net/MyAzureStartPage.aspx, I can also find a perfect deployment, but I can't seem to get the proper home page.
Determining which page to load if none is explicitly specified is a function of the web server. Without configuration changes, the web server is never going to expect to look for your custom page.
Can you not simply rename your desired start page default.aspx? That would be the simplest approach.
Add defaultDocument element in your web.config under configuration/system.webServer node. Something like this will get your default page defined:
<defaultDocument enabled="true">
<files>
<add value="MyAzureStartPage.aspx"/>
</files>
</defaultDocument>

Resources