question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Mini dashboard does not work on meilisearch running on sub routes

See original GitHub issue

Description see issue

The mini dashboard only works when MeiliSearch is running at the root of it’s domain. For example if the instance is hosted here http://mymeili.com then the dashboard will show correctly

If for example the dashboard is in a sub route like http://myapp.com/api then the mini dashboard does not show up.

For example http://104.248.162.211/api/. It is a white page. But if you curl on the same URL

➜  ~ curl http://104.248.162.211/api/health
{"status":"available"}%

Meaning that while the mini dashboard does not show up, meilisearch is still running correctly.

The problematic line is this one in src/App.js:

export const baseUrl =
  process.env.REACT_APP_MEILI_SERVER_ADDRESS ||
  (process.env.NODE_ENV === 'development'
    ? 'http://0.0.0.0:7700'
    : window.location.origin)

window.location.origin takes the root of the domain whereas href takes the current position:

On this page for example

Screenshot 2022-02-09 at 14 03 51

The problem with changing to href is that now the mini dashboard is accessible on every sub-route on not only the root of the meilisearch instance.

example nginx config to reproduce:

server {
    listen 80 default_server;
    listen [::]:80 default_server;

    server_name _;

    location /api/ { # trailing slash is important
        proxy_pass http://127.0.0.1:7700/; # trailing slash is important
    }
}

Expected behavior The mini dashboard should show up at the root of where meilisearch is running

Current behavior It only works when meilisearch is at the root

Environment (please complete the following information):

  • Meilisearch version: v0.25.2

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:4
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

5reactions
urbantroutcommented, Jun 7, 2022

I have adopted @firstred’s answer for nginx:

location /search {
  rewrite /search/(.*) /$1 break;
  proxy_pass http://127.0.0.1:7700;
}

location / {
  if ($http_referer ~* ^.*/search/.*$ ) {
    proxy_pass  http://127.0.0.1:7700;
  }
}
3reactions
firstredcommented, May 5, 2022

Not sure yet what the nginx equivalent is, but I managed to solve the problem with Caddy by matching the Referer header. If the request’s Referer header contains /search/, it will strip /search from the path and effectively serve css js etc. from root.

route {
  ##### Ensure trailing slash
  redir /search /search/

  ##### Serve Meilisearch from a subfolder, by matching the path
  @meilisearch path /search/*
  ##### Serve assets from the subfolder, by matching the HTTP Referer header
  @meilisearch_assets header Referer */search/*

  handle @meilisearch {
    uri strip_prefix /search
    header X-Forwarded-Proto {scheme}
    header X-Forwarded-Host {host}
    reverse_proxy meilisearch:7700
  }

  handle @meilisearch_assets {
    uri strip_prefix /search
    header X-Forwarded-Proto {scheme}
    header X-Forwarded-Host {host}
    reverse_proxy meilisearch:7700
  }
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Deploy a Meilisearch instance on Amazon Web Services (AWS)
The following guide will walk you through every step to deploy Meilisearch in an AWS EC2 instance. If you have any issues with...
Read more >
Nested Route not working in react router dom for my admin ...
The Admin component appears to be missing an Outlet component for the nested routes, or the routes need to be unnested since they...
Read more >
MeiliSearch is a powerful, fast, open-source, easy to use and ...
Click on 'Docker' tab; Copy/Paste the command to start using meilisearch; Check your $(pwd)/data.ms folder on your host machine; No data is ......
Read more >
Laravel Scout - Laravel - The PHP Framework For Web Artisans
MeiliSearch is a blazingly fast and open source search engine. ... While not strictly required to use Scout, you should strongly consider configuring...
Read more >
Configuring searchable attributes the right way - Algolia
A small change in setting searchable attributes could lead to ... You can also set your searchable attributes in your Algolia dashboard.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found