# publicDir does not honour server.basePath

**URL:** <https://discuss.elastic.co/t/publicdir-does-not-honour-server-basepath/205520>\
**Category:** Kibana\
**Created:** [October 28, 2019, 5:02pm UTC](https://discuss.elastic.co/t/publicdir-does-not-honour-server-basepath/205520 "2019-10-28T17:02:48Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Simone\_Scarduzio](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/simone_scarduzio/32/17128_2.png) [@Simone\_Scarduzio](https://discuss.elastic.co/u/Simone_Scarduzio)\
**Post date:** [October 28, 2019, 5:02pm UTC](https://discuss.elastic.co/t/publicdir-does-not-honour-server-basepath/205520/1 "2019-10-28T17:02:48Z")

</div>

Hello, I generated a sample plugin from the Kibana scripts, and added the "publicDir" option in order to serve static files like images from within my plugin:

```auto
// From my plugin's index.js

export default function (kibana) {

  return new kibana.Plugin({
    require: ['kibana'],
    publicDir: resolve(__dirname, 'public'), // <-- I added this to serve static files

    uiExports: {
...

```

* * *

I added a static asset called rhino.png in the "public" subfolder in my plugin directory:

```auto
/me/kibana_plugin/kibana/plugins/my_plugin $ find . | grep png
./public/rhino.png

```

* * *

I generated a zip file for my plugin, so I can install it in a kibana distribution:

```auto
$ yarn build
$ ls build/
my_plugin-0.0.0.zip

```

* * *

I installed the plugin zip in a freshly downloaded Kibana distribution.

```auto
/me/tmp/kibana-7.3.0-darwin-x86_64 $ bin/kibana-plugin install file:///me/kibana_plugin/kibana/plugins/my_plugin/build/my_plugin-0.0.0.zip
Attempting to transfer from file:///me/kibana_plugin/kibana/plugins/my_plugin/build/my_plugin-0.0.0.zip
Transferring 106382 bytes....................
Transfer complete
Retrieving metadata from plugin archive
Extracting plugin archive
Extraction complete
Plugin installation complete

```

* * *

Now I configured a server.basePath in kibana.yml

```auto
/me/tmp/kibana-7.3.0-darwin-x86_64 $ grep basePath config/kibana.yml
# Use the `server.rewriteBasePath` setting to tell Kibana if it should remove the basePath
server.basePath: "/xxx"
...

```

* * *

With Kibana server running, now I expect the following URL to serve the image respecting server.basePath, but it goes 404:

```bash
http://localhost:5601/xxx/plugins/my_plugin/rhino.png <-- 404

```

However, when I remove the basePath from the url, it still works:

```bash
http://localhost:5601/plugins/my_plugin/rhino.png <-- still returns the picture

```

Is there a way to make this work? Is it a bug?

Thanks

---

<div class="post-metadata">

**Author:** ![christophilus](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christophilus/32/42991_2.png) [@christophilus](https://discuss.elastic.co/u/christophilus)\
**Post date:** [October 29, 2019, 4:33pm UTC](https://discuss.elastic.co/t/publicdir-does-not-honour-server-basepath/205520/2 "2019-10-29T16:33:22Z")

</div>

Hm. It seems to be working for me locally with a raw (unzipped) plugin, so there's something else going on. I can't remember ever using png files. I _think_ there's a special "assets" directory which you should add to your plugin, and drop it in there. I'm not sure that they get bundled up in the build process otherwise.

Alternatively, you can import images using `import myimage from './path/to.png'`, and then use the image like that. It's bulkier (I think it inlines it during the build process as a base-64 encoded string).

---

<div class="post-metadata">

**Author:** ![Simone\_Scarduzio](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/simone_scarduzio/32/17128_2.png) [@Simone\_Scarduzio](https://discuss.elastic.co/u/Simone_Scarduzio)\
**Post date:** [October 30, 2019, 3:52pm UTC](https://discuss.elastic.co/t/publicdir-does-not-honour-server-basepath/205520/3 "2019-10-30T15:52:50Z")

</div>

> [@christophilus](#):
>
> It seems to be working for me locally

Are you testing with the Kibana development environment? Because the issue is with the actual zipped Kibana distribution people download and install.

> [@christophilus](#):
>
> it inlines it during the build process as a base-64 encoded string

Wow that would be very inefficient, right? Would it make the optimization phase slower I guess?

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [November 27, 2019, 3:52pm UTC](https://discuss.elastic.co/t/publicdir-does-not-honour-server-basepath/205520/4 "2019-11-27T15:52:52Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
