Segment is stripped when service attempt to load files after http routing


#1

Question regarding path identifier http routing. I have the routing working such that if I make a request to :port/service it gets routed to http/service then to service-latest. The service is a nodejs served website.

The issue I’m having is that when the site loads and looks for static css/js files, the request is being made to :port/style.css rather than :port/service/style.css. I’m not sure why the ‘service’ part of the url is stripped out. Since everything works fine locally (and if I go straight to the service) I thought this might be an issue with my router configuration, given below:

  • label: http-incoming
    # Http rule routing should begin with http
    dstPrefix: /http
    protocol: http
    identifier:
    # Http routing is based on paths
    kind: io.l5d.path
    # Only first segment is used e.g. :port/{segment}
    segments: 1
    # Forward the rest of the path to the handler, e.g. {segment}/path/to/endpoint/ gets passed on
    consume: true
    interpreter:
    kind: io.l5d.namerd
    dst: /$/inet/namerd.ns.svc.cluster.local/4100
    namespace: internal
    servers:
    - port: 4143
    ip: 0.0.0.0

and the rules are:

“prefix”: “/http”,
“dst”: “/#/io.l5d.k8s/ns/http”

“prefix”: “/http/service”,
“dst”: “/http/service-latest | /http/service-latest”

Thanks in advance.


#2

You’ll want to make sure that all your static assets use relative links instead of absolute links in order to preserve the /service prefix. I believe you may also need to access your site with a trailing slash :port/service/ in order for the browser to apply relative links correctly.


#3

Seems like a trailing slash solves the problem - thought I tried this but it must’ve been when the included assets had a leading slash e.g, /style/style.css

This works with a trailing slash in the url:
<link rel="stylesheet" href="style/style.css">

Thanks again.