Skip to content

KibanaDev.dealingWithBasePath

Spencer edited this page Jan 28, 2016 · 1 revision

All communication from the Kibana UI to the server needs to respect the server.basePath. Here are the "blessed" strategies for dealing with this based on the context:

<img> and <a> elements

Write the src or href urls as you would without the base path, but then replace src or href with kbn-src or kbn-href

<img kbn-src="plugins/kibana/images/logo.png">

getting a static asset url

Use webpack to import the asset into the build. This will give you a URL in JavaScript and gives webpack a chance to perform optimizations and cache-busting.

// in plugin/public/main.js
import uiChrome from 'ui/chrome';
import logoUrl from 'plugins/facechimp/assets/banner.png';

uiChrome.setBrand({
  logo: `url(${logoUrl}) center no-repeat`
});

API requests from the front-end

Use chrome.addBasePath() to append the basePath to the front of the url

import chrome from 'ui/chrome';
$http.get(chrome.addBasePath('/api/plugin/things'))

Server side

Append config.get('server.basePath') to any previously absolute path

const basePath = server.config().get('server.basePath')
server.route({
  path: '/redirect',
  handler(req, reply) {
    reply.redirect(`${basePath}/otherLocation`);
  }
})