Merge branch 'release/1.0.2' into production
This commit is contained in:
commit
4a26b8d1ba
|
@ -15,8 +15,8 @@ var Product = loopback.Model.extend('product');
|
||||||
Product.attachTo(loopback.memory());
|
Product.attachTo(loopback.memory());
|
||||||
app.model(Product);
|
app.model(Product);
|
||||||
|
|
||||||
app.use(loopback.rest());
|
app.use('/api', loopback.rest());
|
||||||
app.use('/explorer', explorer(app));
|
app.use('/explorer', explorer(app, { basePath: '/api' }));
|
||||||
|
|
||||||
app.listen(3000);
|
app.listen(3000);
|
||||||
```
|
```
|
||||||
|
|
25
index.js
25
index.js
|
@ -3,8 +3,8 @@
|
||||||
*/
|
*/
|
||||||
var path = require('path');
|
var path = require('path');
|
||||||
var loopback = require('loopback');
|
var loopback = require('loopback');
|
||||||
var swagger = require('loopback/node_modules/strong-remoting/ext/swagger');
|
var swagger = requireLoopbackDependency('strong-remoting/ext/swagger');
|
||||||
var express = require('loopback/node_modules/express');
|
var express = requireLoopbackDependency('express');
|
||||||
var STATIC_ROOT = path.join(__dirname, 'public');
|
var STATIC_ROOT = path.join(__dirname, 'public');
|
||||||
|
|
||||||
module.exports = explorer;
|
module.exports = explorer;
|
||||||
|
@ -30,3 +30,24 @@ function explorer(loopbackApplication, options) {
|
||||||
app.use(loopback.static(STATIC_ROOT));
|
app.use(loopback.static(STATIC_ROOT));
|
||||||
return app;
|
return app;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function requireLoopbackDependency(module) {
|
||||||
|
try {
|
||||||
|
return require('loopback/node_modules/' + module);
|
||||||
|
} catch (err) {
|
||||||
|
if (err.code !== 'MODULE_NOT_FOUND') throw err;
|
||||||
|
try {
|
||||||
|
// Dependencies may be installed outside the loopback module,
|
||||||
|
// e.g. as peer dependencies. Try to load the dependency from there.
|
||||||
|
return require(module);
|
||||||
|
} catch (errPeer) {
|
||||||
|
if (errPeer.code !== 'MODULE_NOT_FOUND') throw errPeer;
|
||||||
|
// Rethrow the initial error to make it clear that we were trying
|
||||||
|
// to load a module that should have been installed inside
|
||||||
|
// "loopback/node_modules". This should minimise end-user's confusion.
|
||||||
|
// However, such situation should never happen as `require('loopback')`
|
||||||
|
// would have failed before this function was even called.
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "loopback-explorer",
|
"name": "loopback-explorer",
|
||||||
"version": "1.0.1",
|
"version": "1.0.2",
|
||||||
"description": "Browse and test your LoopBack app's APIs",
|
"description": "Browse and test your LoopBack app's APIs",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|
|
@ -71,8 +71,12 @@ describe('explorer', function() {
|
||||||
app.use(restUrlBase, loopback.rest());
|
app.use(restUrlBase, loopback.rest());
|
||||||
app.use('/explorer', explorer(app, { basePath: restUrlBase }));
|
app.use('/explorer', explorer(app, { basePath: restUrlBase }));
|
||||||
} else {
|
} else {
|
||||||
app.use(loopback.rest());
|
// LoopBack REST adapter owns the whole URL space and does not
|
||||||
|
// let other middleware handle same URLs.
|
||||||
|
// It's possible to circumvent this measure by installing
|
||||||
|
// the explorer middleware before the REST middleware.
|
||||||
app.use('/explorer', explorer(app));
|
app.use('/explorer', explorer(app));
|
||||||
|
app.use(loopback.rest());
|
||||||
}
|
}
|
||||||
done();
|
done();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue