Can only access backend with trailing slash

Hi there,

I’m experimenting with kong in docker (docker kong:1.1) and added some services with routes (for example TheiaIDE and as route /testroute). The thing is, I can only access my backend when I add a trailing slash on the url like http://localhost:8000/testroute/.

When I try this with http://localhost:8000/testroute I simply get a white page and the console shows 404 error. This is bad for my because I want to secure my backend with some userparameters. Anything I forgot adding the services?

I have a setup script here:

https://paste.ubuntu.com/p/gXwt4SKCWr/

Hi,
Welcome to kong nation.
The thing is that you are not really try and route to an API but to TheiaIDE.
When you access to http://localhost:8000/testroute then your browser try and load http://localhost:8000/bundle.js whereas when you access http://localhost:8000/testroute/ then http://localhost:8000/testroute/bundle.js is called.
In the first case, you do not have the corresponding route defined in kong.
In the second case, it uses your route (/testroute) and send the additional path (bundle.js) to your upstream server.

As a side note, looking at your script, note that you can add a route to a service by using the POST /services/service-name/routes syntax
For example:

curl -i -X POST
–url http://localhost:8001/services/service-v1/routes
–data ‘paths[]=/test1’

Hi tr00mb,

thanks for the warm welcome!

So to sum it up, since I’m trying to access a WebApp and not an API, I’ll get those 404 errors since my application is not really aware of this proxy situation and it tries to call it’s further files on standard root path?
In order to fix it (for the first case), I’d have to add a billion of additional routes for each file in the WebApp?

Is there a possible solution for this or should I try my luck with nginx+rewrite+proxy set-ups?

Best Regards

In did the src="./bundle.js" in the home page of TheiaIDE is difficult to handle without a / in your url.

It depends what you want to do in terms of plugins, but testing it with http://localhost:8000/testroute/ (with the trailing /) should work to access all the webapp

Regards
Yohann

Hello,

I know this an old question but I’m facing the same issue and I was wondering if anyone could help.

I’m using Kong 2.1 with db-less configuration and one of the services that I’m proxying is a webapp.

For this webapp I’ve defined a route /hello/world/app because I’d like users to access the webapp through https://www.mydomain.com/hello/world/app and https://www.mydomain.com/hello/world/app/ (I really don’t know if this a good idea or bad practice)

Some users forget to add the trailing slash and it’s very confusing for them because instead of the webapp they get a blank page.

This is the service definition:

- name: app
  routes:
  - https_redirect_status_code: 301
    name: app
    paths:
    - /hello/world/app
    protocols:
    - https
    strip_path: true
  url: http://app.default.svc.cluster.local:80

This is happens because, as @tr00mb said, the js and css files requests are missing part of the path. Specifically the js and css are requested like https://www.mydomain.com/hello/world/js/XXXX.js and https://www.mydomain.com/hello/world/css/XXXX.css instead of https://www.mydomain.com/hello/world/app/js/XXXX.js and https://www.mydomain.com/hello/world/app/css/XXXX.css.

How can I work around this? Is there a way to add a trailing slash to the request if it is missing?

Thank you.