Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SDKS-2199] Add Cors. Fix listener destroy. Update changes file #109

Open
wants to merge 2 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion CHANGES.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
2.1.1 (XXX XX, 2022)
- Updated SDK version to v10.22.0 which is the latest to the date.
- Added new env variable to enable cors
- Added Multi environment support
- Added new env variables:
- SPLIT_EVALUATOR_ENVIRONMENTS
- SPLIT_EVALUATOR_ENABLE_CORS

2.1.0 (Jul 15, 2022)
- Added support for attribute values to be sent as JSON in a POST version of the get treatment endpoints, to avoid query param limitations.
- Updated the SDK version to 10.20.0 which is the latest to the date.
- Updated the SDK version to 10.20.0 which is the latest to the date.
- Updated npm dependencies for vulnerability fixes.
- Updated base image to node:16.16.0-alpine3.16

Expand Down
22 changes: 22 additions & 0 deletions __tests__/cors.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
const request = require('supertest');

describe('CORS ', () => {
beforeEach(() => {
jest.resetModules();
});

test('', async () => {
process.env.SPLIT_EVALUATOR_ENABLE_CORS = true;
const app = require('../app');
const { headers } = await request(app).get('/');
expect(headers['access-control-allow-origin']).toEqual('*');
});

test('default', async () => {
delete process.env.SPLIT_EVALUATOR_ENABLE_CORS;
const app = require('../app');
const { headers } = await request(app).get('/');
expect(headers['access-control-allow-origin']).toEqual(undefined);
});

});
6 changes: 6 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ const adminRouter = require('./admin/admin.router');

// Utils
const utils = require('./utils/utils');
// Cors
if (process.env.SPLIT_EVALUATOR_ENABLE_CORS === 'true') {
console[console.warn ? 'warn' : 'log']('Cors enabled');
const cors = require('cors');
app.use(cors());
}

app.use(morgan('tiny'));

Expand Down
1 change: 1 addition & 0 deletions listener/manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ const ImpressionManagerFactory = (function(){
return instance;
},
async destroy() {
if (!instance) return;
await instance.destroy();
instance = undefined;
},
Expand Down
35 changes: 35 additions & 0 deletions package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"dependencies": {
"@splitsoftware/splitio": "10.22.0",
"config": "1.25.1",
"cors": "^2.8.5",
"express": "^4.17.1",
"morgan": "^1.9.1",
"npm": "^8.13.2",
Expand Down