Skip to content
Closed
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
5 changes: 2 additions & 3 deletions lib/compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,14 @@ module.exports = function compile(options) {
ConfigLoader.loadDataSources(dsRootDir, env);
assertIsValidConfig('data source', dataSourcesConfig);

// not configurable yet
var middlewareRootDir = appRootDir;
var middlewareRootDir = options.middlewareRootDir || appRootDir;

var middlewareConfig = options.middleware ||
ConfigLoader.loadMiddleware(middlewareRootDir, env);
var middlewareInstructions =
buildMiddlewareInstructions(middlewareRootDir, middlewareConfig);

var componentRootDir = appRootDir; // not configurable yet
var componentRootDir = options.componentRootDir || appRootDir;
var componentConfig = options.components ||
ConfigLoader.loadComponents(componentRootDir, env);
var componentInstructions =
Expand Down
57 changes: 57 additions & 0 deletions test/compiler.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1595,6 +1595,39 @@ describe('compiler', function() {
sourceFileForUrlNotFound);
});

it('supports `middlewareRootDir` option', function() {
var middlewareJson = {
initial: {},
custom: {
'loopback/server/middleware/url-not-found': {
params: 'some-config-data',
},
},
};
var customDir = path.resolve(appdir.PATH, 'custom');
fs.mkdirsSync(customDir);
fs.writeJsonSync(path.resolve(customDir, 'middleware.json'),
middlewareJson);

var instructions = boot.compile({
appRootDir: appdir.PATH,
middlewareRootDir: path.resolve(appdir.PATH, 'custom'),
});

expect(instructions.middleware).to.eql({
phases: ['initial', 'custom'],
middleware: [
{
sourceFile: sourceFileForUrlNotFound,
config: {
phase: 'custom',
params: 'some-config-data',
},
},
],
});
});

it('fails when a module middleware cannot be resolved', function() {
appdir.writeConfigFileSync('middleware.json', {
final: {
Expand Down Expand Up @@ -2238,6 +2271,30 @@ describe('compiler', function() {
});
});

it('supports `componentRootDir` option', function() {
var componentJson = {
debug: {
option: 'value',
},
};
var customDir = path.resolve(appdir.PATH, 'custom');
fs.mkdirsSync(customDir);
fs.writeJsonSync(
path.resolve(customDir, 'component-config.json'), componentJson);

var instructions = boot.compile({
appRootDir: appdir.PATH,
componentRootDir: path.resolve(appdir.PATH, 'custom'),
});
var component = instructions.components[0];
expect(component).to.eql({
sourceFile: require.resolve('debug'),
config: {
option: 'value',
},
});
});

it('loads component relative to appRootDir', function() {
appdir.writeConfigFileSync('./component-config.json', {
'./index': { },
Expand Down