Skip to content

Commit 57522fc

Browse files
committed
[api] Automatically apply CORS to the /api only
1 parent 99eafd0 commit 57522fc

File tree

6 files changed

+14
-35
lines changed

6 files changed

+14
-35
lines changed

desktop/conf.dist/hue.ini

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -233,9 +233,6 @@
233233
# Timeout in seconds for REST calls.
234234
## rest_conn_timeout=120
235235

236-
# To set to true when using a decoupled UI.
237-
## cors_enabled=false
238-
239236
# A json file containing a list of log redaction rules for cleaning sensitive data
240237
# from log files. It is defined as:
241238
#

desktop/conf/pseudo-distributed.ini.tmpl

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -237,9 +237,6 @@
237237
# Timeout in seconds for REST calls.
238238
## rest_conn_timeout=120
239239

240-
# To set to true when using a decoupled UI.
241-
## cors_enabled=false
242-
243240
# A json file containing a list of log redaction rules for cleaning sensitive data
244241
# from log files. It is defined as:
245242
#

desktop/core/src/desktop/conf.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -575,13 +575,6 @@ def get_auth_password():
575575
type=int,
576576
help=_('Timeout in seconds for REST calls.'))
577577

578-
CORS_ENABLED = Config(
579-
key="cors_enabled",
580-
help=_("To set to true when using a decoupled UI."),
581-
type=coerce_bool,
582-
default=False
583-
)
584-
585578

586579
VCS = UnspecifiedConfigSection(
587580
"vcs",

desktop/core/src/desktop/settings.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -379,14 +379,13 @@
379379

380380

381381
# Permissive CORS for public /api
382-
if desktop.conf.CORS_ENABLED.get() or True:
383-
INSTALLED_APPS.append('corsheaders')
384-
MIDDLEWARE.insert(0, 'corsheaders.middleware.CorsMiddleware')
385-
CORS_URLS_REGEX = r'^/api/.*$'
386-
if sys.version_info[0] > 2:
387-
CORS_ALLOW_ALL_ORIGINS = True
388-
else:
389-
CORS_ORIGIN_ALLOW_ALL = True
382+
INSTALLED_APPS.append('corsheaders')
383+
MIDDLEWARE.insert(0, 'corsheaders.middleware.CorsMiddleware')
384+
CORS_URLS_REGEX = r'^/api/.*$'
385+
if sys.version_info[0] > 2:
386+
CORS_ALLOW_ALL_ORIGINS = True
387+
else:
388+
CORS_ORIGIN_ALLOW_ALL = True
390389

391390
# Configure database
392391
if os.getenv('DESKTOP_DB_CONFIG'):

docs/docs-site/content/developer/components/scratchpad/_index.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,7 @@ First install the NPM [package](/developer/components/) and import the component
4747

4848
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*.
4949

50-
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
51-
50+
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.
5251

5352
It is possible to skip the `npm install` and directly grab the module via:
5453

tools/examples/components/sql-scratchpad/README.md

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,15 @@ There are two ways to import the SQL Scratchpad:
1919

2020
## Use the published package
2121

22-
1. Setup Hue to allow CORS, in your hue .ini add:
23-
```
24-
[desktop]
25-
cors_enabled=true
26-
```
27-
2. Go to the example project `cd tools/examples/components/sql-scratchpad`
28-
3. `npm install`
29-
4. `npm start`
30-
5. Open [http://localhost:3000](http://localhost:3000) to view it in the browser.
22+
1. Go to the example project `cd tools/examples/components/sql-scratchpad`
23+
2. `npm install`
24+
3. `npm start`
25+
4. Open [http://localhost:3000](http://localhost:3000) to view it in the browser.
3126

3227

3328
## Use your local package
3429

35-
1. In the SQL Scratchpad project change the "gethue" dependency in `package.json` to
30+
1. In the SQL Scratchpad project change the "gethue" dependency in `package.json` to
3631
```
3732
"gethue": "file:../../../../npm_dist",
3833
```
@@ -43,7 +38,7 @@ There are two ways to import the SQL Scratchpad:
4338
7. `npm install`
4439
8. `npm start`
4540

46-
It will monitor changes of the related Hue sources and update npm_dist when needed, if the
41+
It will monitor changes of the related Hue sources and update npm_dist when needed, if the
4742
SQL Scratchpad project doesn't pick up the changes a restart of the app might be needed.
4843

4944

@@ -52,4 +47,3 @@ SQL Scratchpad project doesn't pick up the changes a restart of the app might be
5247
1. `npx create-react-app sql-scratchpad --template typescript`
5348
2. Add `"gethue": "file:../../../../npm_dist"` to dependencies in package.json
5449
3. Add `SKIP_PREFLIGHT_CHECK=true` to .env (required when using local Hue package)
55-

0 commit comments

Comments
 (0)