Merge pull request #83 from strongloop/feature/allow-string-in-uidirs
Allow `uiDirs` to be defined as a String
This commit is contained in:
commit
409dfdc2bb
4
index.js
4
index.js
|
@ -52,10 +52,14 @@ function explorer(loopbackApplication, options) {
|
||||||
// In this way one could e.g. make changes to index.html without having
|
// In this way one could e.g. make changes to index.html without having
|
||||||
// to worry about constantly pulling in JS updates.
|
// to worry about constantly pulling in JS updates.
|
||||||
if (options.uiDirs) {
|
if (options.uiDirs) {
|
||||||
|
if (typeof options.uiDirs === 'string') {
|
||||||
|
app.use(express.static(options.uiDirs));
|
||||||
|
} else if (Array.isArray(options.uiDirs)) {
|
||||||
options.uiDirs.forEach(function(dir) {
|
options.uiDirs.forEach(function(dir) {
|
||||||
app.use(express.static(dir));
|
app.use(express.static(dir));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (options.swaggerDistRoot) {
|
if (options.swaggerDistRoot) {
|
||||||
console.warn('loopback-explorer: `swaggerDistRoot` is deprecated,' +
|
console.warn('loopback-explorer: `swaggerDistRoot` is deprecated,' +
|
||||||
|
|
|
@ -106,6 +106,37 @@ describe('explorer', function() {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('when specifying custom static file root directories', function() {
|
||||||
|
var app;
|
||||||
|
beforeEach(function() {
|
||||||
|
app = loopback();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should allow `uiDirs` to be defined as an Array', function(done) {
|
||||||
|
app.use('/explorer', explorer(app, {
|
||||||
|
uiDirs: [ path.resolve(__dirname, 'fixtures', 'dummy-swagger-ui') ]
|
||||||
|
}));
|
||||||
|
|
||||||
|
request(app).get('/explorer/')
|
||||||
|
.expect(200)
|
||||||
|
// expect the content of `dummy-swagger-ui/index.html`
|
||||||
|
.expect('custom index.html\n')
|
||||||
|
.end(done);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should allow `uiDirs` to be defined as an String', function(done) {
|
||||||
|
app.use('/explorer', explorer(app, {
|
||||||
|
uiDirs: path.resolve(__dirname, 'fixtures', 'dummy-swagger-ui')
|
||||||
|
}));
|
||||||
|
|
||||||
|
request(app).get('/explorer/')
|
||||||
|
.expect(200)
|
||||||
|
// expect the content of `dummy-swagger-ui/index.html`
|
||||||
|
.expect('custom index.html\n')
|
||||||
|
.end(done);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
function givenLoopBackAppWithExplorer(explorerBase) {
|
function givenLoopBackAppWithExplorer(explorerBase) {
|
||||||
return function(done) {
|
return function(done) {
|
||||||
var app = this.app = loopback();
|
var app = this.app = loopback();
|
||||||
|
|
Loading…
Reference in New Issue