Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

prefix in webui.json doesn't affact #741

Closed
Cnily03 opened this issue Jan 27, 2025 · 11 comments
Closed

prefix in webui.json doesn't affact #741

Cnily03 opened this issue Jan 27, 2025 · 11 comments
Labels
bug Something isn't working

Comments

@Cnily03
Copy link

Cnily03 commented Jan 27, 2025

系统版本

(Docker)

QQNT 版本

/

NapCat 版本

4.4.15

OneBot 客户端

/

发生了什么?

prefix in webui.json doesn't affact on frontend.

如何复现

webui.json:

{
    "host": "0.0.0.0",
    "port": 6099,
    "token": "xxx",
    "loginRate": 3,
    "prefix": "/xxx/napcat"
}

Nginx:

server_name test.example.com
listen 80;
location /xxx/napcat/ {
    proxy_pass http://127.0.0.1:6099/;
}

Visiting http://test.example.com/xxx/napcat/webui, successfully returned html file. But it requests js file with root

Image

Thougn it was due to vite configuration:

base: '/webui/',

The /api requests ignored prefix too:

Image

期望的结果?

Changing /webui/ base to ./ may solve the issue if no routes is taken. Or replace /webui/ with prefix at the backend if mimetype is text/html

What if dynamicly load webui.json at frontend?

NapCat 运行日志

OneBot 客户端运行日志

@Cnily03 Cnily03 added the bug Something isn't working label Jan 27, 2025
@Cnily03 Cnily03 changed the title [BUG] prefix in webui.json doesn't affact Jan 27, 2025
@Cnily03
Copy link
Author

Cnily03 commented Jan 27, 2025

version 4.2 works, what if turn some configuration back?

@bietiaop
Copy link
Collaborator

bietiaop commented Jan 28, 2025

Since the switch to React, the default routing method has been changed to History Router. If baseURL is changed to the relative path ./, then when accessing a multi-level path, the resource path will not match correctly. For example:
When accessing /debug/http, the browser should request /a.js, but because the relative path ./ is configured, the browser will mistakenly request /debug/a.js.
In addition, the jump within the page still follows baseURL + absolute path. When the prefix is ​​added, the jump within the page is still baseURL + absolute path instead of baseURL + prefix + absolute path, because this path has been determined when the frontend was builded. If a relative path is configured, the path error problem mentioned at the beginning will also occur. The same is true even when using Ngnix or Apache.
Of course if you have any good ideas you can bring them up and we can solve them together.

@Cnily03
Copy link
Author

Cnily03 commented Jan 30, 2025

If we change BrowserRouter to HashRouter

<BrowserRouter basename="/webui/">

  <HashRouter>
    <Provider>
      <App />
    </Provider>
  </HashRouter >

The routes would like xxx/#/dashboard instead of xxx/dashboard

and change baseUrl from /webui/ to .

    base: '.',
    server: {
      proxy: {
        '/api': backendDebugUrl
      }
    },

we can start an integrated proxy server to serve static files, or configure the nginx by users themselves.

import config from 'path/to/webui.json'

// `config.prefix`/webui/xxx returns `static_directory`/xxx 
// proxy `config.prefix`/api/* to API server

@bietiaop
Copy link
Collaborator

We will use hash to locate some elements in the future, such as debug page quick locate, to locate the configuration item by hash, so that when sharing the url to other people, they will be able to locate the configuration item or debugging interface location directly through the url (through the browser's ability). If we use hashRouter, the browser's hash localization feature will not work. In this case, we will use the search parameter to achieve similar functionality, but when the user enters the browser page for the first time through the terminal, it will carry a token parameter, and when the login is complete, using the hashRouter to make the jump will result in the browser address becoming something like this: ?token=123/#/. And hashRouter is the early browser does not support history api history product, he will occupy the browser hash location function, now has gradually abandoned the use of hash routing.

@Cnily03
Copy link
Author

Cnily03 commented Jan 30, 2025

Seems that there's no better way. Actually I prefer the prefix feature bacause I have 2 account, and I use nginx server to route /napcat/a to a account and /napcat/b to b account. If the api server allows the multi-account route switch, it might solve my problem.

@bietiaop
Copy link
Collaborator

sorry, to avoid some grey industries, we won't support multiple accounts

@Cnily03
Copy link
Author

Cnily03 commented Jan 30, 2025

Another way is to register service worker if https enables. But i think it's not an elegent way as it may pollute user's browser. and it brings troube when creating breaking changes

@bietiaop
Copy link
Collaborator

No, we're not thinking about multi-account situations for now. In fact, for most people, to run an entertainment bot, just need to log in to one account at the same time.

@Cnily03
Copy link
Author

Cnily03 commented Jan 30, 2025

I understand.

@Cnily03
Copy link
Author

Cnily03 commented Jan 30, 2025

So in fact the prefix configuration is deprecated. it's better to note at the document.

@bietiaop
Copy link
Collaborator

In fact, the default config file no longer contains the prefix config item when running the latest version for the first time. This version is a large update release. We have limited members and we focus on feathers first. Document updates will have delays.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants