Skip to content

Commit

Permalink
Merge pull request #85 from AbegaM/fix_cors_error
Browse files Browse the repository at this point in the history
Fix cors origin error in the CLI
  • Loading branch information
thevahidal authored Jun 30, 2023
2 parents 3dd1d76 + 0fff753 commit 6036d0a
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 6 deletions.
4 changes: 2 additions & 2 deletions core/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion core/package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
3 changes: 2 additions & 1 deletion core/src/config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
10 changes: 8 additions & 2 deletions core/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,19 @@ app.use(bodyParser.json());
db.pragma('journal_mode = WAL');

// Enable CORS
let corsOrigin = config.cors.origin;

if (corsOrigin.includes('*')) {
corsOrigin = '*';
}

const corsOptions = {
origin: config.cors.origin,
origin: corsOrigin,
};

app.use(cors(corsOptions));

// Log requests

if (config.verbose !== null) {
app.use(
expressWinston.logger({
Expand Down

0 comments on commit 6036d0a

Please sign in to comment.