vvbbnn00 / WARP-Clash-API

该项目可以让你通过订阅的方式使用Cloudflare WARP+,自动获取流量。This project enables you to use Cloudflare WARP+ through subscription, automatically acquiring traffic.
GNU General Public License v3.0
8.52k stars 1.16k forks source link

feat: ✨ Support nginx secondary directory proxy #164

Closed FocusProgram closed 7 months ago

vvbbnn00 commented 7 months ago

Thank you for submitting the pull request. I understand your requirement to ensure that relative paths remain valid even when reverse proxies and base paths are modified.

However, using location.href as the baseUrl may not be the best approach, as it returns the complete URL of the current page and could lead to incorrect URLs when appending additional paths.

Instead, I suggest using location.origin combined with the directory part of location.pathname as the baseUrl. This approach ensures that the relative paths point to the correct location, even in the case of reverse proxies and modified base paths. Here is an example of how you can construct the baseUrl:

// Get the directory part of location.pathname
const basePath = location.pathname.substring(0, location.pathname.lastIndexOf('/') + 1);

// Construct the baseUrl
const baseUrl = location.origin + basePath;

With this baseUrl, you can concatenate other paths, ensuring that the generated URLs are correct whether accessed directly or through a reverse proxy.

FocusProgram commented 7 months ago

location.href is indeed not the best way to implement