Skip to content

Commit

Permalink
Fix errors when using HTTPS and Cloudflare
Browse files Browse the repository at this point in the history
  • Loading branch information
clarkwinkelmann committed Dec 20, 2022
1 parent 8caf968 commit e7da4a4
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/MeilisearchDashboardMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface
// Replace links to resources which don't include the subfolder
$content = preg_replace('~(src|href)="/([^"]+\.(?:png|svg|js|json))"~', '$1="/meilisearch/$2"', $content);
// Inject base path for use later
$content = str_replace('</head><body>', '</head><body><script>window.FLARUM_ORIGIN=' . json_encode('//' . $request->getUri()->getHost() . '/meilisearch') . '</script>', $content);
$content = str_replace('</head><body>', '</head><body><script>window.FLARUM_ORIGIN=' . json_encode($request->getUri()->getScheme() . '://' . $request->getUri()->getHost() . '/meilisearch') . '</script>', $content);
// Change the base URL in the compiled javascript otherwise API requests to go the root
$content = str_replace('window.location.origin', 'window.FLARUM_ORIGIN ' /* spaces to be same length for sourcemap */, $content);

Expand All @@ -69,6 +69,6 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface
fwrite($stream, $content);
rewind($stream);

return $response->withBody(new Stream($stream));
return $response->withoutHeader('Content-Length')->withBody(new Stream($stream));
}
}

0 comments on commit e7da4a4

Please sign in to comment.