Skip to content

Commit cc7e94f

Browse files
authored
Use different API route according the ENV (#13597)
### What problem does this PR solve? 1. Fix go server date precision 2. Use API_SCHEME_PROXY to control the web API route ### Type of change - [x] New Feature (non-breaking change which adds functionality) --------- Signed-off-by: Jin Hai <haijin.chn@gmail.com>
1 parent 1569ed8 commit cc7e94f

File tree

14 files changed

+140
-73
lines changed

14 files changed

+140
-73
lines changed

build.sh

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ PROJECT_ROOT="$SCRIPT_DIR"
1414
# Build directories
1515
CPP_DIR="$PROJECT_ROOT/internal/cpp"
1616
BUILD_DIR="$CPP_DIR/cmake-build-release"
17-
OUTPUT_BINARY="$PROJECT_ROOT/bin/server_main"
17+
RAGFLOW_SERVER_BINARY="$PROJECT_ROOT/bin/server_main"
18+
ADMIN_SERVER_BINARY="$PROJECT_ROOT/bin/admin_server"
1819

1920
echo -e "${GREEN}=== RAGFlow Go Server Build Script ===${NC}"
2021

@@ -90,31 +91,47 @@ build_go() {
9091
sudo apt -y install libpcre2-dev
9192
fi
9293

93-
echo "Building Go binary: $OUTPUT_BINARY"
94-
GOPROXY=${GOPROXY:-https://goproxy.cn,https://proxy.golang.org,direct} CGO_ENABLED=1 go build -o "$OUTPUT_BINARY" ./cmd/server_main.go
95-
GOPROXY=${GOPROXY:-https://goproxy.cn,https://proxy.golang.org,direct} CGO_ENABLED=1 go build -o "$OUTPUT_BINARY" ./cmd/admin_server.go
94+
echo "Building API server binary: $RAGFLOW_SERVER_BINARY and $ADMIN_SERVER_BINARY"
95+
GOPROXY=${GOPROXY:-https://goproxy.cn,https://proxy.golang.org,direct} CGO_ENABLED=1 go build -o "$RAGFLOW_SERVER_BINARY" ./cmd/server_main.go
96+
GOPROXY=${GOPROXY:-https://goproxy.cn,https://proxy.golang.org,direct} CGO_ENABLED=1 go build -o "$ADMIN_SERVER_BINARY" ./cmd/admin_server.go
9697

97-
if [ ! -f "$OUTPUT_BINARY" ]; then
98-
echo -e "${RED}Error: Failed to build Go binary${NC}"
98+
if [ ! -f "$RAGFLOW_SERVER_BINARY" ]; then
99+
echo -e "${RED}Error: Failed to build RAGFlow server binary${NC}"
99100
exit 1
100101
fi
101-
102-
echo -e "${GREEN}✓ Go server built successfully: $OUTPUT_BINARY${NC}"
102+
103+
if [ ! -f "$ADMIN_SERVER_BINARY" ]; then
104+
echo -e "${RED}Error: Failed to build Admin server binary${NC}"
105+
exit 1
106+
fi
107+
108+
echo -e "${GREEN}✓ Go server_main built successfully: $RAGFLOW_SERVER_BINARY${NC}"
109+
echo -e "${GREEN}✓ Go admin_server built successfully: $ADMIN_SERVER_BINARY${NC}"
103110
}
104111

105112
# Clean build artifacts
106113
clean() {
107114
print_section "Cleaning build artifacts"
108115

109116
rm -rf "$BUILD_DIR"
110-
rm -f "$OUTPUT_BINARY"
111-
117+
rm -f "$RAGFLOW_SERVER_BINARY"
118+
rm -f "$ADMIN_SERVER_BINARY"
119+
112120
echo -e "${GREEN}✓ Build artifacts cleaned${NC}"
113121
}
114122

115123
# Run the server
116124
run() {
117-
if [ ! -f "$OUTPUT_BINARY" ]; then
125+
if [ ! -f "$ADMIN_SERVER_BINARY" ]; then
126+
echo -e "${RED}Error: Binary not found. Build first with --all or --go${NC}"
127+
exit 1
128+
fi
129+
130+
print_section "Starting ADMIN server"
131+
cd "$PROJECT_ROOT"
132+
./admin_server
133+
134+
if [ ! -f "$RAGFLOW_SERVER_BINARY" ]; then
118135
echo -e "${RED}Error: Binary not found. Build first with --all or --go${NC}"
119136
exit 1
120137
fi
@@ -184,7 +201,7 @@ main() {
184201
build_cpp
185202
build_go
186203
echo -e "\n${GREEN}=== Build completed successfully! ===${NC}"
187-
echo "Binary: $OUTPUT_BINARY"
204+
echo "Binary: $RAGFLOW_SERVER_BINARY, $ADMIN_SERVER_BINARY"
188205
;;
189206
*)
190207
echo -e "${RED}Unknown option: $1${NC}"

docker/.env

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,9 @@ SVR_MCP_PORT=9382
155155
GO_HTTP_PORT=9384
156156
GO_ADMIN_PORT=9385
157157

158+
# API_PROXY_SCHEME=hybrid # go and python hybrid deploy mode
159+
API_PROXY_SCHEME=python # use pure python server deployment
160+
158161
# The RAGFlow Docker image to download. v0.22+ doesn't include embedding models.
159162
RAGFLOW_IMAGE=infiniflow/ragflow:v0.24.0
160163

docker/docker-compose.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ services:
3434
- ${SVR_HTTP_PORT}:9380
3535
- ${ADMIN_SVR_HTTP_PORT}:9381
3636
- ${SVR_MCP_PORT}:9382 # entry for MCP (host_port:docker_port). The docker_port must match the value you set for `mcp-port` above.
37+
- ${GO_HTTP_PORT}:9384
38+
- ${GO_ADMIN_PORT}:9385
3739
volumes:
3840
- ./ragflow-logs:/ragflow/logs
3941
- ./nginx/ragflow.conf:/etc/nginx/conf.d/ragflow.conf

docker/entrypoint.sh

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,11 @@ if [[ "${ENABLE_WEBSERVER}" -eq 1 ]]; then
230230
echo "Starting ragflow_server..."
231231
while true; do
232232
"$PY" api/ragflow_server.py ${INIT_SUPERUSER_ARGS} &
233-
bin/server_main &
233+
234+
if [[ "${API_PROXY_SCHEME}" == "hybrid" ]]; then
235+
echo "Starting RAGFlow server in hybrid mode..."
236+
bin/server_main &
237+
fi
234238
wait;
235239
sleep 1;
236240
done &
@@ -249,7 +253,10 @@ if [[ "${ENABLE_ADMIN_SERVER}" -eq 1 ]]; then
249253
echo "Starting admin_server..."
250254
while true; do
251255
"$PY" admin/server/admin_server.py &
252-
bin/admin_server &
256+
if [[ "${API_PROXY_SCHEME}" == "hybrid" ]]; then
257+
echo "Starting Admin server in hybrid mode..."
258+
bin/admin_server &
259+
fi
253260
wait;
254261
sleep 1;
255262
done &

internal/admin/service.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ func (s *Service) CreateUser(username, password, role string) (map[string]interf
183183
isSuperuser := role == "admin"
184184

185185
now := time.Now().Unix()
186-
nowDate := time.Now()
186+
nowDate := time.Now().Truncate(time.Second)
187187

188188
user := &model.User{
189189
ID: userID,
@@ -440,7 +440,7 @@ func (s *Service) getInitTenantLLM(userID string) ([]*model.TenantLLM, error) {
440440
llmName := llm.LLMName
441441
modelType := llm.ModelType
442442
now := time.Now().Unix()
443-
nowDate := time.Now()
443+
nowDate := time.Now().Truncate(time.Second)
444444

445445
tenantLLM := &model.TenantLLM{
446446
TenantID: userID,
@@ -1559,7 +1559,7 @@ func (s *Service) InitDefaultAdmin() error {
15591559

15601560
if len(users) == 0 {
15611561
now := time.Now().Unix()
1562-
nowDate := time.Now()
1562+
nowDate := time.Now().Truncate(time.Second)
15631563
userID := utility.GenerateToken()
15641564
accessToken := utility.GenerateToken()
15651565
status := "1"
@@ -1635,7 +1635,7 @@ func (s *Service) InitDefaultAdmin() error {
16351635
// addTenantForAdmin add tenant for admin user
16361636
func (s *Service) addTenantForAdmin(userID, nickname string) error {
16371637
now := time.Now().Unix()
1638-
nowDate := time.Now()
1638+
nowDate := time.Now().Truncate(time.Second)
16391639
status := "1"
16401640
role := "owner"
16411641
tenantName := nickname + "'s Kingdom"

internal/dao/kb.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ func (dao *KnowledgebaseDAO) DuplicateName(name, tenantID string) string {
293293
// This matches the Python atomic_increase_doc_num_by_id method
294294
func (dao *KnowledgebaseDAO) AtomicIncreaseDocNumByID(kbID string) error {
295295
now := time.Now().Unix()
296-
nowDate := time.Now()
296+
nowDate := time.Now().Truncate(time.Second)
297297
return DB.Model(&model.Knowledgebase{}).
298298
Where("id = ?", kbID).
299299
Updates(map[string]interface{}{
@@ -307,7 +307,7 @@ func (dao *KnowledgebaseDAO) AtomicIncreaseDocNumByID(kbID string) error {
307307
// This matches the Python decrease_document_num_in_delete method
308308
func (dao *KnowledgebaseDAO) DecreaseDocumentNum(kbID string, docNum, chunkNum, tokenNum int64) error {
309309
now := time.Now().Unix()
310-
nowDate := time.Now()
310+
nowDate := time.Now().Truncate(time.Second)
311311
return DB.Model(&model.Knowledgebase{}).
312312
Where("id = ?", kbID).
313313
Updates(map[string]interface{}{

internal/dao/system_settings.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ func (d *SystemSettingsDAO) GetByName(name string) ([]model.SystemSettings, erro
5959
// Updates the setting with the given name using the provided data
6060
func (d *SystemSettingsDAO) UpdateByName(name string, setting *model.SystemSettings) error {
6161
now := time.Now().Unix()
62-
nowDate := time.Now()
62+
nowDate := time.Now().Truncate(time.Second)
6363

6464
return DB.Model(&model.SystemSettings{}).
6565
Where("name = ?", name).
@@ -76,7 +76,7 @@ func (d *SystemSettingsDAO) UpdateByName(name string, setting *model.SystemSetti
7676
// Inserts a new system setting record into database
7777
func (d *SystemSettingsDAO) Create(setting *model.SystemSettings) error {
7878
now := time.Now().Unix()
79-
nowDate := time.Now()
79+
nowDate := time.Now().Truncate(time.Second)
8080

8181
setting.CreateTime = &now
8282
setting.CreateDate = &nowDate
@@ -161,7 +161,7 @@ func (d *SystemSettingsDAO) Transaction(fn func(tx *gorm.DB) error) error {
161161
// CreateWithTx create setting within transaction
162162
func (d *SystemSettingsDAO) CreateWithTx(tx *gorm.DB, setting *model.SystemSettings) error {
163163
now := time.Now().Unix()
164-
nowDate := time.Now()
164+
nowDate := time.Now().Truncate(time.Second)
165165

166166
setting.CreateTime = &now
167167
setting.CreateDate = &nowDate
@@ -174,7 +174,7 @@ func (d *SystemSettingsDAO) CreateWithTx(tx *gorm.DB, setting *model.SystemSetti
174174
// UpdateByNameWithTx update setting within transaction
175175
func (d *SystemSettingsDAO) UpdateByNameWithTx(tx *gorm.DB, name string, setting *model.SystemSettings) error {
176176
now := time.Now().Unix()
177-
nowDate := time.Now()
177+
nowDate := time.Now().Truncate(time.Second)
178178

179179
return tx.Model(&model.SystemSettings{}).
180180
Where("name = ?", name).

internal/handler/auth.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ func (h *AuthHandler) AuthMiddleware() gin.HandlerFunc {
6767
if *user.IsSuperuser {
6868
c.JSON(http.StatusForbidden, gin.H{
6969
"code": common.CodeForbidden,
70-
"message": "Super user should access the URL",
70+
"message": "Super user shouldn't access the URL",
7171
})
7272
return
7373
}

internal/handler/user.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -336,14 +336,6 @@ func (h *UserHandler) Logout(c *gin.Context) {
336336
return
337337
}
338338

339-
if *user.IsSuperuser {
340-
c.JSON(http.StatusForbidden, gin.H{
341-
"code": common.CodeForbidden,
342-
"message": "Super user should access the URL",
343-
})
344-
return
345-
}
346-
347339
// Logout user
348340
code, err = h.userService.Logout(user)
349341
if err != nil {

internal/service/chat.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,7 @@ func (s *ChatService) SetDialog(userID string, req *SetDialogRequest) (*SetDialo
434434
}
435435

436436
// Get current time
437-
now := time.Now()
437+
now := time.Now().Truncate(time.Second)
438438
createTime := now.UnixMilli()
439439

440440
// Set default language
@@ -479,7 +479,7 @@ func (s *ChatService) SetDialog(userID string, req *SetDialogRequest) (*SetDialo
479479
}
480480

481481
// Update existing chat - also update update_time
482-
now := time.Now()
482+
now := time.Now().Truncate(time.Second)
483483
updateTime := now.UnixMilli()
484484
updateData := map[string]interface{}{
485485
"name": name,

0 commit comments

Comments
 (0)