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

NEXT_PUBLIC_BASE_PATH 异常 #7006

Closed
coder2z opened this issue Mar 17, 2025 · 11 comments
Closed

NEXT_PUBLIC_BASE_PATH 异常 #7006

coder2z opened this issue Mar 17, 2025 · 11 comments
Labels
🐛 Bug Something isn't working | 缺陷 unconfirm 未被维护者确认的问题

Comments

@coder2z
Copy link

coder2z commented Mar 17, 2025

📦 部署环境

Docker

📦 部署模式

服务端模式(lobe-chat-database 镜像)

📌 软件版本

latest

💻 系统环境

Ubuntu

🌐 浏览器

Chrome

🐛 问题描述

通过 Dockerfile.database 按照如下命令构建镜像

docker build -t aaaa.com/lobechat-database:test-v1 \
              --build-arg NEXT_PUBLIC_BASE_PATH=/lobechat \
              --build-arg NEXT_PUBLIC_ENABLE_NEXT_AUTH=1  -f ./Dockerfile.database .

启动:

E:\code\lobe-chat\lobe-chat-code>podman run --env-file=./.env.local -p 3210:3210 aaaa.com/lobechat-database:test-v1
🌐 DNS Server: [ '192.168.127.1' ]
-------------------------------------
[Database] Start to migration...
✅ database migration pass.
-------------------------------------
   ▲ Next.js 15.2.2
   - Local:        http://localhost:3210
   - Network:      http://0.0.0.0:3210

 ✓ Starting...
 ✓ Ready in 43ms

.env.local file:

APP_URL=http://127.0.0.1:3210
NEXT_PUBLIC_SERVICE_MODE=server
DATABASE_URL=postgres://postgres_admin:[email protected]:5432/lobechat-dev
DATABASE_DRIVER=node
NEXT_PUBLIC_BASE_PATH=/lobechat
ENABLED_OLLAMA=0
ENABLED_OPENAI=0
DEEPSEEK_PROXY_URL=http://xxxx:8000/v1
DEEPSEEK_API_KEY=123456
DEEPSEEK_MODEL_LIST=-all,+deepseek-reasoner
DEFAULT_AGENT_CONFIG=model=deepseek-reasoner;provider=deepseek
FEATURE_FLAGS=+pin_list,+welcome_suggest,-speech_to_text,+knowledge_base,-clerk_sign_up,-check_updates,-dalle,-edit_agent,-openai_proxy_url,-openai_api_key,-language_model_settings,-provider_settings,-changelog

启动后通过:http://localhost:3210/lobechat 访问会出现 404,通过 http://localhost:3210/lobechat/lobechat 访问会出现loading页面,但是后续还是会302 到 http://localhost:3210/lobechat 导致404

📷 复现步骤

No response

🚦 期望结果

如上

📝 补充信息

如上

@coder2z coder2z added the unconfirm 未被维护者确认的问题 label Mar 17, 2025
@lobehubbot
Copy link
Member

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


📦 Deployment environment

Docker

📦 Deployment mode

Server-side mode (lobe-chat-database mirror)

📌 Software version

Latest

💻 System environment

Ubuntu

🌐 Browser

Chrome

🐛 Question description

Build the image through Dockerfile.database according to the following command

docker build -t aaaa.com/lobechat-database:test-v1 \
              --build-arg NEXT_PUBLIC_BASE_PATH=/lobechat \
              --build-arg NEXT_PUBLIC_ENABLE_NEXT_AUTH=1 -f ./Dockerfile.database .

start up:

E:\code\lobe-chat\lobe-chat-code>podman run --env-file=./.env.local -p 3210:3210 aaaa.com/lobechat-database:test-v1
🌐 DNS Server: [ '192.168.127.1' ]
-------------------------------------
[Database] Start to migration...
✅ database migration pass.
-------------------------------------
   ▲ Next.js 15.2.2
   - Local: http://localhost:3210
   - Network: http://0.0.0.0:3210

 ✓ Starting...
 ✓ Ready in 43ms

.env.local file:

APP_URL=http://127.0.0.1:3210
NEXT_PUBLIC_SERVICE_MODE=server
DATABASE_URL=postgres://postgres_admin:[email protected]:5432/lobechat-dev
DATABASE_DRIVER=node
NEXT_PUBLIC_BASE_PATH=/lobechat
ENABLED_OLLAMA=0
ENABLED_OPENAI=0
DEEPSEEK_PROXY_URL=http://xxxx:8000/v1
DEEPSEEK_API_KEY=123456
DEEPSEEK_MODEL_LIST=-all,+deepseek-reasoner
DEFAULT_AGENT_CONFIG=model=deepseek-reasoner;provider=deepseek
FEATURE_FLAGS=+pin_list,+welcome_suggest,-speech_to_text,+knowledge_base,-clerk_sign_up,-check_updates,-dalle,-edit_agent,-openai_proxy_url,-openai_api_key,-language_model_settings,-provider_settings,-changelog

After starting, accessing through: http://localhost:3210/lobechat will appear 404. When accessing through http://localhost:3210/lobechat/lobechat, the loading page will appear, but in the future, it will still reach http://localhost:3210/lobechat, resulting in 404.

📷 Reproduction steps

No response

🚦 Expected results

As above

📝 Supplementary information

As above

@lobehubbot
Copy link
Member

👀 @coder2z

Thank you for raising an issue. We will investigate into the matter and get back to you as soon as possible.
Please make sure you have given us as much context as possible.
非常感谢您提交 issue。我们会尽快调查此事,并尽快回复您。 请确保您已经提供了尽可能多的背景信息。

@dosubot dosubot bot added the 🐛 Bug Something isn't working | 缺陷 label Mar 17, 2025
@github-project-automation github-project-automation bot moved this to Roadmap - Chat 1.x in Lobe Chat Routine Mar 17, 2025
Copy link

dosubot bot commented Mar 17, 2025

Hey @coder2z, I'm here to help you with your coding bugs and answer any questions you may have. Let's squash those bugs together! 🤖

I found a similar unsolved discussion titled "NEXT_PUBLIC_BASE_PATH not work with docker" [1]. This might be related to the issue you're experiencing with the NEXT_PUBLIC_BASE_PATH in your Docker setup.

To address the 404 error when accessing the application with a custom base path, ensure that the NEXT_PUBLIC_BASE_PATH is correctly configured in both the build and runtime environments. Here are some steps you can follow:

  1. Verify Docker Build Arguments: Ensure that the --build-arg NEXT_PUBLIC_BASE_PATH=/lobechat is correctly passed during the Docker build process. This should set the base path in the built image.

  2. Check Environment Variables: Make sure that the .env.local file used during runtime includes the correct NEXT_PUBLIC_BASE_PATH=/lobechat.

  3. Review Next.js Configuration: Ensure that the next.config.ts file in your project is correctly using the basePath configuration. It should look something like this:

    const basePath = process.env.NEXT_PUBLIC_BASE_PATH;
    
    const nextConfig = {
      basePath,
      // other configurations...
    };
    
    module.exports = nextConfig;
  4. Inspect Redirects: Check the redirects configuration in next.config.ts to ensure that any redirects are correctly handling the base path.

  5. Rebuild and Redeploy: After making these changes, rebuild your Docker image and redeploy the application to see if the issue is resolved.

These steps should help ensure that the NEXT_PUBLIC_BASE_PATH is correctly applied and prevent 404 errors when accessing the application.

To continue talking to Dosu, mention @dosu.


Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Bug Report | Other

Copy link

dosubot bot commented Mar 17, 2025

The issue you're experiencing with the NEXT_PUBLIC_BASE_PATH environment variable causing 404 errors and incorrect redirects might be related to how the base path is being processed and utilized in the application.

  1. Ensure Correct Base Path Configuration: The NEXT_PUBLIC_BASE_PATH is used to set a base path for the application. Make sure that all routes and assets are correctly prefixed with this base path. In your case, it should be /lobechat.

  2. Middleware and Routing Configuration: Check the middleware configuration to ensure that it correctly handles the base path. The middleware should rewrite URLs to include the base path. If there is an error in constructing the nextPathname variable, it could lead to incorrect redirects [1].

  3. Docker Environment Variables: Verify that the environment variable NEXT_PUBLIC_BASE_PATH is correctly set during both the build and run phases of your Docker setup. This variable should be accessible to the application at runtime.

  4. Check for Double Prefixing: The issue where accessing /lobechat/lobechat leads to a loading page suggests that there might be a double prefixing of the base path. Ensure that the base path is not being appended multiple times in your routing logic.

  5. Review .env.local Configuration: Ensure that the .env.local file is correctly configured and that there are no conflicting settings that might affect the base path handling.

By addressing these points, you should be able to resolve the 404 errors and ensure that the application correctly handles the base path.

To continue talking to Dosu, mention @dosu.


Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Bug Report | Other

@coder2z
Copy link
Author

coder2z commented Mar 17, 2025

这里确认 环境变量设置成功,我进入容器后打印过

@lobehubbot
Copy link
Member

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


Confirm here that the environment variable is set successfully. I printed it after entering the container.

@arvinxx
Copy link
Contributor

arvinxx commented Mar 17, 2025

basePath 已经计划废弃

@arvinxx arvinxx closed this as not planned Won't fix, can't repro, duplicate, stale Mar 17, 2025
@github-project-automation github-project-automation bot moved this from Roadmap - Chat 1.x to Done in Lobe Chat Routine Mar 17, 2025
@lobehubbot
Copy link
Member

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


basePath is already planned to be abandoned

@lobehubbot
Copy link
Member

@coder2z

This issue is closed, If you have any questions, you can comment and reply.
此问题已经关闭。如果您有任何问题,可以留言并回复。

@coder2z
Copy link
Author

coder2z commented Mar 17, 2025

如果需要的话 应该如何处理呢?网关 rewrite 的方式吗?

@lobehubbot
Copy link
Member

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


What should I do if I need it? Is the way to rewrite the gateway?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 Bug Something isn't working | 缺陷 unconfirm 未被维护者确认的问题
Projects
Status: Done
Development

No branches or pull requests

3 participants