mirror of
https://github.com/Unleash/unleash.git
synced 2025-01-01 00:08:27 +01:00
Merge pull request #166 from Unleash/api_path
Introduces the /api path.
This commit is contained in:
commit
820caee65b
@ -12,7 +12,7 @@ const path = require('path');
|
|||||||
|
|
||||||
module.exports = function (config) {
|
module.exports = function (config) {
|
||||||
const app = express();
|
const app = express();
|
||||||
const router = express.Router(); // eslint-disable-line new-cap
|
|
||||||
const baseUriPath = config.baseUriPath || '';
|
const baseUriPath = config.baseUriPath || '';
|
||||||
const publicFolder = config.publicFolder;
|
const publicFolder = config.publicFolder;
|
||||||
|
|
||||||
@ -37,7 +37,13 @@ module.exports = function (config) {
|
|||||||
}));
|
}));
|
||||||
|
|
||||||
// Setup API routes
|
// Setup API routes
|
||||||
routes.create(router, config);
|
const apiRouter = express.Router(); // eslint-disable-line new-cap
|
||||||
|
routes.createAPI(apiRouter, config);
|
||||||
|
app.use(`${baseUriPath}/api/`, apiRouter);
|
||||||
|
|
||||||
|
// Setup deprecated routes
|
||||||
|
const router = express.Router(); // eslint-disable-line new-cap
|
||||||
|
routes.createLegacy(router, config);
|
||||||
app.use(baseUriPath, router);
|
app.use(baseUriPath, router);
|
||||||
|
|
||||||
if (process.env.NODE_ENV !== 'production') {
|
if (process.env.NODE_ENV !== 'production') {
|
||||||
|
@ -1,10 +1,16 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
exports.create = function (app, config) {
|
|
||||||
require('./event')(app, config);
|
exports.createAPI = function (router, config) {
|
||||||
require('./feature')(app, config);
|
require('./event')(router, config);
|
||||||
require('./feature-archive')(app, config);
|
require('./feature')(router, config);
|
||||||
require('./strategy')(app, config);
|
require('./feature-archive')(router, config);
|
||||||
require('./health-check')(app, config);
|
require('./strategy')(router, config);
|
||||||
require('./metrics')(app, config);
|
require('./health-check')(router, config);
|
||||||
|
require('./metrics')(router, config);
|
||||||
|
};
|
||||||
|
|
||||||
|
exports.createLegacy = function (router, config) {
|
||||||
|
require('./feature')(router, config);
|
||||||
|
require('./health-check')(router, config);
|
||||||
};
|
};
|
||||||
|
@ -5,14 +5,14 @@ const request = require('./test-helper').request;
|
|||||||
describe('The event api', () => {
|
describe('The event api', () => {
|
||||||
it('returns events', done => {
|
it('returns events', done => {
|
||||||
request
|
request
|
||||||
.get('/events')
|
.get('/api/events')
|
||||||
.expect('Content-Type', /json/)
|
.expect('Content-Type', /json/)
|
||||||
.expect(200, done);
|
.expect(200, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('returns events given a name', done => {
|
it('returns events given a name', done => {
|
||||||
request
|
request
|
||||||
.get('/events/myname')
|
.get('/api/events/myname')
|
||||||
.expect('Content-Type', /json/)
|
.expect('Content-Type', /json/)
|
||||||
.expect(200, done);
|
.expect(200, done);
|
||||||
});
|
});
|
||||||
|
@ -58,7 +58,7 @@ describe('The features api', () => {
|
|||||||
.set('Content-Type', 'application/json')
|
.set('Content-Type', 'application/json')
|
||||||
.end(() => {
|
.end(() => {
|
||||||
request
|
request
|
||||||
.get('/events')
|
.get('/api/events')
|
||||||
.end((err, res) => {
|
.end((err, res) => {
|
||||||
assert.equal(res.body.events[0].createdBy, 'ivaosthu');
|
assert.equal(res.body.events[0].createdBy, 'ivaosthu');
|
||||||
done();
|
done();
|
||||||
|
@ -16,7 +16,7 @@ describe('The archive features api', () => {
|
|||||||
|
|
||||||
it('returns three archived toggles', done => {
|
it('returns three archived toggles', done => {
|
||||||
request
|
request
|
||||||
.get('/archive/features')
|
.get('/api/archive/features')
|
||||||
.expect('Content-Type', /json/)
|
.expect('Content-Type', /json/)
|
||||||
.expect(200)
|
.expect(200)
|
||||||
.end((err, res) => {
|
.end((err, res) => {
|
||||||
@ -27,7 +27,7 @@ describe('The archive features api', () => {
|
|||||||
|
|
||||||
it('revives a feature by name', done => {
|
it('revives a feature by name', done => {
|
||||||
request
|
request
|
||||||
.post('/archive/revive')
|
.post('/api/archive/revive')
|
||||||
.send({ name: 'featureArchivedX' })
|
.send({ name: 'featureArchivedX' })
|
||||||
.set('Content-Type', 'application/json')
|
.set('Content-Type', 'application/json')
|
||||||
.expect(200, done);
|
.expect(200, done);
|
||||||
@ -35,7 +35,7 @@ describe('The archive features api', () => {
|
|||||||
|
|
||||||
it('must set name when reviving toggle', done => {
|
it('must set name when reviving toggle', done => {
|
||||||
request
|
request
|
||||||
.post('/archive/revive')
|
.post('/api/archive/revive')
|
||||||
.send({ name: '' })
|
.send({ name: '' })
|
||||||
.expect(400, done);
|
.expect(400, done);
|
||||||
});
|
});
|
||||||
|
@ -12,28 +12,28 @@ describe('The strategy api', () => {
|
|||||||
|
|
||||||
it('gets all strategies', done => {
|
it('gets all strategies', done => {
|
||||||
request
|
request
|
||||||
.get('/strategies')
|
.get('/api/strategies')
|
||||||
.expect('Content-Type', /json/)
|
.expect('Content-Type', /json/)
|
||||||
.expect(200, done);
|
.expect(200, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('gets a strategy by name', done => {
|
it('gets a strategy by name', done => {
|
||||||
request
|
request
|
||||||
.get('/strategies/default')
|
.get('/api/strategies/default')
|
||||||
.expect('Content-Type', /json/)
|
.expect('Content-Type', /json/)
|
||||||
.expect(200, done);
|
.expect(200, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('cant get a strategy by name that dose not exist', done => {
|
it('cant get a strategy by name that dose not exist', done => {
|
||||||
request
|
request
|
||||||
.get('/strategies/mystrategy')
|
.get('/api/strategies/mystrategy')
|
||||||
.expect('Content-Type', /json/)
|
.expect('Content-Type', /json/)
|
||||||
.expect(404, done);
|
.expect(404, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('creates a new strategy', done => {
|
it('creates a new strategy', done => {
|
||||||
request
|
request
|
||||||
.post('/strategies')
|
.post('/api/strategies')
|
||||||
.send({ name: 'myCustomStrategy', description: 'Best strategy ever.' })
|
.send({ name: 'myCustomStrategy', description: 'Best strategy ever.' })
|
||||||
.set('Content-Type', 'application/json')
|
.set('Content-Type', 'application/json')
|
||||||
.expect(201, done);
|
.expect(201, done);
|
||||||
@ -41,7 +41,7 @@ describe('The strategy api', () => {
|
|||||||
|
|
||||||
it('requires new strategies to have a name', done => {
|
it('requires new strategies to have a name', done => {
|
||||||
request
|
request
|
||||||
.post('/strategies')
|
.post('/api/strategies')
|
||||||
.send({ name: '' })
|
.send({ name: '' })
|
||||||
.set('Content-Type', 'application/json')
|
.set('Content-Type', 'application/json')
|
||||||
.expect(400, done);
|
.expect(400, done);
|
||||||
@ -49,7 +49,7 @@ describe('The strategy api', () => {
|
|||||||
|
|
||||||
it('refuses to create a strategy with an existing name', done => {
|
it('refuses to create a strategy with an existing name', done => {
|
||||||
request
|
request
|
||||||
.post('/strategies')
|
.post('/api/strategies')
|
||||||
.send({ name: 'default' })
|
.send({ name: 'default' })
|
||||||
.set('Content-Type', 'application/json')
|
.set('Content-Type', 'application/json')
|
||||||
.expect(403, done);
|
.expect(403, done);
|
||||||
@ -57,13 +57,13 @@ describe('The strategy api', () => {
|
|||||||
|
|
||||||
it('deletes a new strategy', done => {
|
it('deletes a new strategy', done => {
|
||||||
request
|
request
|
||||||
.delete('/strategies/usersWithEmail')
|
.delete('/api/strategies/usersWithEmail')
|
||||||
.expect(200, done);
|
.expect(200, done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('can\'t delete a strategy that dose not exist', done => {
|
it('can\'t delete a strategy that dose not exist', done => {
|
||||||
request
|
request
|
||||||
.delete('/strategies/unknown')
|
.delete('/api/strategies/unknown')
|
||||||
.expect(404, done);
|
.expect(404, done);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -33,7 +33,7 @@ describe('Unit: The strategies api', () => {
|
|||||||
|
|
||||||
it('should add version numbers for /stategies', (done) => {
|
it('should add version numbers for /stategies', (done) => {
|
||||||
request
|
request
|
||||||
.get('/strategies')
|
.get('/api/strategies')
|
||||||
.expect('Content-Type', /json/)
|
.expect('Content-Type', /json/)
|
||||||
.expect(200)
|
.expect(200)
|
||||||
.end((err, res) => {
|
.end((err, res) => {
|
||||||
|
Loading…
Reference in New Issue
Block a user