Parcourir la source

Feat/optimize install wildcard support (#53)

John Wang il y a 1 an
Parent
commit
8847bb1e45
3 fichiers modifiés avec 24 ajouts et 20 suppressions
  1. 3 3
      api/models/model.py
  2. 20 16
      docker/docker-compose.yaml
  3. 1 1
      docker/nginx/conf.d/default.conf

+ 3 - 3
api/models/model.py

@@ -1,6 +1,6 @@
 import json
 
-from flask import current_app
+from flask import current_app, request
 from flask_login import UserMixin
 from sqlalchemy.dialects.postgresql import UUID
 
@@ -56,7 +56,7 @@ class App(db.Model):
 
     @property
     def api_base_url(self):
-        return current_app.config['API_URL'] + '/v1'
+        return (current_app.config['API_URL'] if current_app.config['API_URL'] else request.host_url.rstrip('/')) + '/v1'
 
     @property
     def tenant(self):
@@ -505,7 +505,7 @@ class Site(db.Model):
 
     @property
     def app_base_url(self):
-        return current_app.config['APP_URL']
+        return (current_app.config['APP_URL'] if current_app.config['APP_URL'] else request.host_url.rstrip('/')) + '/v1'
 
 
 class ApiToken(db.Model):

+ 20 - 16
docker/docker-compose.yaml

@@ -11,12 +11,18 @@ services:
       LOG_LEVEL: INFO
       # A secret key that is used for securely signing the session cookie and encrypting sensitive information on the database. You can generate a strong key using `openssl rand -base64 42`.
       SECRET_KEY: sk-9f73s3ljTXVcMT3Blb3ljTqtsKiGHXVcMT3BlbkFJLK7U
-      # The base URL of console application, refers to the Console base URL of WEB service.
-      CONSOLE_URL: http://localhost
-      # The URL for Service API endpoints,refers to the base URL of the current API service.
-      API_URL: http://localhost
-      # The URL for Web APP, refers to the Web App base URL of WEB service.
-      APP_URL: http://localhost
+      # The base URL of console application, refers to the Console base URL of WEB service if console domain is
+      # different from api or web app domain.
+      # example: http://cloud.dify.ai
+      CONSOLE_URL: ''
+      # The URL for Service API endpoints,refers to the base URL of the current API service if api domain is
+      # different from console domain.
+      # example: http://api.dify.ai
+      API_URL: ''
+      # The URL for Web APP, refers to the Web App base URL of WEB service if web app domain is different from
+      # console or api domain.
+      # example: http://udify.app
+      APP_URL: ''
       # When enabled, migrations will be executed prior to application startup and the application will start after the migrations have completed.
       MIGRATION_ENABLED: 'true'
       # The configurations of postgres database connection.
@@ -113,12 +119,6 @@ services:
       # A secret key that is used for securely signing the session cookie and encrypting sensitive information on the database. You can generate a strong key using `openssl rand -base64 42`.
       # same as the API service
       SECRET_KEY: sk-9f73s3ljTXVcMT3Blb3ljTqtsKiGHXVcMT3BlbkFJLK7U
-      # The base URL of console application, refers to the Console base URL of WEB service.
-      CONSOLE_URL: http://localhost
-      # The URL for Service API endpoints,refers to the base URL of the current API service.
-      API_URL: http://localhost
-      # The URL for Web APP, refers to the Web App base URL of WEB service.
-      APP_URL: http://localhost
       # The configurations of postgres database connection.
       # It is consistent with the configuration in the 'db' service below.
       DB_USERNAME: postgres
@@ -154,10 +154,14 @@ services:
     restart: always
     environment:
       EDITION: SELF_HOSTED
-      # The base URL of console application, refers to the Console base URL of WEB service.
-      CONSOLE_URL: http://localhost
-      # The URL for Web APP, refers to the Web App base URL of WEB service.
-      APP_URL: http://localhost
+      # The base URL of console application, refers to the Console base URL of WEB service if console domain is
+      # different from api or web app domain.
+      # example: http://cloud.dify.ai
+      CONSOLE_URL: ''
+      # The URL for Web APP, refers to the Web App base URL of WEB service if web app domain is different from
+      # console or api domain.
+      # example: http://udify.app
+      APP_URL: ''
 
   # The postgres database.
   db:

+ 1 - 1
docker/nginx/conf.d/default.conf

@@ -1,6 +1,6 @@
 server {
     listen 80;
-    server_name localhost;
+    server_name _;
 
     location /console/api {
       proxy_pass http://api:5001;