Explorar o código

[api] Automatically apply CORS to the /api only

Romain Rigaux %!s(int64=4) %!d(string=hai) anos
pai
achega
57522fc31f

+ 0 - 3
desktop/conf.dist/hue.ini

@@ -233,9 +233,6 @@
   # Timeout in seconds for REST calls.
   ## rest_conn_timeout=120
 
-  # To set to true when using a decoupled UI.
-  ## cors_enabled=false
-
   # A json file containing a list of log redaction rules for cleaning sensitive data
   # from log files. It is defined as:
   #

+ 0 - 3
desktop/conf/pseudo-distributed.ini.tmpl

@@ -237,9 +237,6 @@
   # Timeout in seconds for REST calls.
   ## rest_conn_timeout=120
 
-  # To set to true when using a decoupled UI.
-  ## cors_enabled=false
-
   # A json file containing a list of log redaction rules for cleaning sensitive data
   # from log files. It is defined as:
   #

+ 0 - 7
desktop/core/src/desktop/conf.py

@@ -575,13 +575,6 @@ REST_CONN_TIMEOUT = Config(
   type=int,
   help=_('Timeout in seconds for REST calls.'))
 
-CORS_ENABLED = Config(
-  key="cors_enabled",
-  help=_("To set to true when using a decoupled UI."),
-  type=coerce_bool,
-  default=False
-)
-
 
 VCS = UnspecifiedConfigSection(
   "vcs",

+ 7 - 8
desktop/core/src/desktop/settings.py

@@ -379,14 +379,13 @@ EMAIL_SUBJECT_PREFIX = 'Hue %s - ' % desktop.conf.CLUSTER_ID.get()
 
 
 # Permissive CORS for public /api
-if desktop.conf.CORS_ENABLED.get() or True:
-  INSTALLED_APPS.append('corsheaders')
-  MIDDLEWARE.insert(0, 'corsheaders.middleware.CorsMiddleware')
-  CORS_URLS_REGEX = r'^/api/.*$'
-  if sys.version_info[0] > 2:
-    CORS_ALLOW_ALL_ORIGINS = True
-  else:
-    CORS_ORIGIN_ALLOW_ALL = True
+INSTALLED_APPS.append('corsheaders')
+MIDDLEWARE.insert(0, 'corsheaders.middleware.CorsMiddleware')
+CORS_URLS_REGEX = r'^/api/.*$'
+if sys.version_info[0] > 2:
+  CORS_ALLOW_ALL_ORIGINS = True
+else:
+  CORS_ORIGIN_ALLOW_ALL = True
 
 # Configure database
 if os.getenv('DESKTOP_DB_CONFIG'):

+ 1 - 2
docs/docs-site/content/developer/components/scratchpad/_index.md

@@ -47,8 +47,7 @@ First install the NPM [package](/developer/components/) and import the component
 
 Then make sure *api-url* points to a running Hue or [Compose](https://github.com/gethue/compose) APIs. The API is the middleware between your Data Warehouse and Web Browser client and will provide the dynamic content like the list of tables and columns and enrich the static autocomplete powered by the [parser](/developer/components/parsers/) selected by the *dialect*.
 
-Specify the credentials for the authentication via *username="demo" password="demo"*. An option to look-up a local JWT token and not require the credentials is coming shortly
-
+Specify the credentials for the authentication via *username="demo" password="demo"*. An option to look-up a local JWT token and not require the credentials is coming shortly.
 
 It is possible to skip the `npm install` and directly grab the module via:
 

+ 6 - 12
tools/examples/components/sql-scratchpad/README.md

@@ -19,20 +19,15 @@ There are two ways to import the SQL Scratchpad:
 
 ## Use the published package
 
-1. Setup Hue to allow CORS, in your hue .ini add:
-```
-  [desktop]
-  cors_enabled=true
-```
-2. Go to the example project `cd tools/examples/components/sql-scratchpad`
-3. `npm install`
-4. `npm start`
-5. Open [http://localhost:3000](http://localhost:3000) to view it in the browser.
+1. Go to the example project `cd tools/examples/components/sql-scratchpad`
+2. `npm install`
+3. `npm start`
+4. Open [http://localhost:3000](http://localhost:3000) to view it in the browser.
 
 
 ## Use your local package
 
-1. In the SQL Scratchpad project change the "gethue" dependency in `package.json` to 
+1. In the SQL Scratchpad project change the "gethue" dependency in `package.json` to
    ```
    "gethue": "file:../../../../npm_dist",
    ```
@@ -43,7 +38,7 @@ There are two ways to import the SQL Scratchpad:
 7. `npm install`
 8. `npm start`
 
-It will monitor changes of the related Hue sources and update npm_dist when needed, if the 
+It will monitor changes of the related Hue sources and update npm_dist when needed, if the
 SQL Scratchpad project doesn't pick up the changes a restart of the app might be needed.
 
 
@@ -52,4 +47,3 @@ SQL Scratchpad project doesn't pick up the changes a restart of the app might be
 1. `npx create-react-app sql-scratchpad --template typescript`
 2. Add `"gethue": "file:../../../../npm_dist"` to dependencies in package.json
 3. Add `SKIP_PREFLIGHT_CHECK=true` to .env (required when using local Hue package)
-