From 6241d2b2903dfb322867a67e159d689c1037055a Mon Sep 17 00:00:00 2001 From: AbegaM Date: Tue, 20 Jun 2023 19:48:53 +0300 Subject: [PATCH 1/3] Fix cors origin error in the cli --- README.md | 2 +- core/src/config/index.js | 3 ++- core/src/index.js | 4 +++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index da694fc..f365b14 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ Install Soul CLI with npm ## Usage Soul is command line tool, after installing it, -Run `soul -d sqlite.db -p 8000` and it'll start a REST API on [http://localhost:8000](http://localhost:8000) and a Websocket server on [ws://localhost:8000](ws://localhost:8000). +Run `soul -d sqlite.db -p 8000 -c "*"` and it'll start a REST API on [http://localhost:8000](http://localhost:8000) and a Websocket server on [ws://localhost:8000](ws://localhost:8000). ```bash Usage: soul [options] diff --git a/core/src/config/index.js b/core/src/config/index.js index 1eb4d17..6b94b92 100644 --- a/core/src/config/index.js +++ b/core/src/config/index.js @@ -75,7 +75,8 @@ module.exports = { filename: argv.database || envVars.DB || ':memory:', }, cors: { - origin: argv.cors.split(',') || envVars.CORS_ORIGIN_WHITELIST.split(','), + origin: argv.cors?.split(',') || + envVars.CORS_ORIGIN_WHITELIST?.split(',') || ['*'], }, rateLimit: { enabled: argv['rate-limit-enabled'] || envVars.RATE_LIMIT_ENABLED, diff --git a/core/src/index.js b/core/src/index.js index 04ea0aa..b39005d 100755 --- a/core/src/index.js +++ b/core/src/index.js @@ -28,9 +28,11 @@ app.use(bodyParser.json()); db.pragma('journal_mode = WAL'); // Enable CORS +const corsOrigin = config.cors.origin; const corsOptions = { - origin: config.cors.origin, + origin: corsOrigin[0] === '*' ? '*' : corsOrigin, }; + app.use(cors(corsOptions)); // Log requests From f6c3ae7d29127364f0a507eace787d5013ffa4ce Mon Sep 17 00:00:00 2001 From: AbegaM Date: Fri, 30 Jun 2023 18:33:33 +0300 Subject: [PATCH 2/3] Simplify CORS origin handling + Update README file --- README.md | 2 +- core/src/index.js | 10 +++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index f365b14..da694fc 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ Install Soul CLI with npm ## Usage Soul is command line tool, after installing it, -Run `soul -d sqlite.db -p 8000 -c "*"` and it'll start a REST API on [http://localhost:8000](http://localhost:8000) and a Websocket server on [ws://localhost:8000](ws://localhost:8000). +Run `soul -d sqlite.db -p 8000` and it'll start a REST API on [http://localhost:8000](http://localhost:8000) and a Websocket server on [ws://localhost:8000](ws://localhost:8000). ```bash Usage: soul [options] diff --git a/core/src/index.js b/core/src/index.js index b39005d..cfb22d6 100755 --- a/core/src/index.js +++ b/core/src/index.js @@ -28,15 +28,19 @@ app.use(bodyParser.json()); db.pragma('journal_mode = WAL'); // Enable CORS -const corsOrigin = config.cors.origin; +let corsOrigin = config.cors.origin; + +if (corsOrigin.includes('*')) { + corsOrigin = '*'; +} + const corsOptions = { - origin: corsOrigin[0] === '*' ? '*' : corsOrigin, + origin: corsOrigin, }; app.use(cors(corsOptions)); // Log requests - if (config.verbose !== null) { app.use( expressWinston.logger({ From 0fff753dd705ac941f1b9484f1809f0b583adc83 Mon Sep 17 00:00:00 2001 From: AbegaM Date: Fri, 30 Jun 2023 18:42:25 +0300 Subject: [PATCH 3/3] Increase minor version --- core/package-lock.json | 4 ++-- core/package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/core/package-lock.json b/core/package-lock.json index 7145cd2..d8b0e68 100644 --- a/core/package-lock.json +++ b/core/package-lock.json @@ -1,12 +1,12 @@ { "name": "soul-cli", - "version": "0.2.2", + "version": "0.3.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "soul-cli", - "version": "0.2.2", + "version": "0.3.0", "license": "MIT", "dependencies": { "better-sqlite3": "^8.1.0", diff --git a/core/package.json b/core/package.json index fe1409c..fa53946 100644 --- a/core/package.json +++ b/core/package.json @@ -1,6 +1,6 @@ { "name": "soul-cli", - "version": "0.2.2", + "version": "0.3.0", "description": "A SQLite REST and Realtime server", "main": "src/server.js", "bin": {