add support for absolute middleware paths on win32

uses simple regex check to test if a path matches NTFS notation
This commit is contained in:
Benjamin Kroeger 2016-11-29 10:57:42 +01:00
parent 9cb3d0648b
commit 49016b4e66
2 changed files with 20 additions and 1 deletions

View File

@ -381,7 +381,10 @@ function tryResolveAppPath(rootDir, relativePath, resolveOptions) {
resolveOptions = resolveOptions || { strict: true }; resolveOptions = resolveOptions || { strict: true };
var isModuleRelative = false; var isModuleRelative = false;
if (relativePath[0] === '/') { // would love to use `path.isAbsolute(relativePath)` from node's core module `path`
// but unfortunately that is not available in node v0.10.x
// https://nodejs.org/dist/latest-v6.x/docs/api/path.html#path_path_isabsolute_path
if (relativePath[0] === '/' || /^[a-zA-Z]:[\\]{1,2}/.test(relativePath)) {
fullPath = relativePath; fullPath = relativePath;
} else if (start === './' || start === '..') { } else if (start === './' || start === '..') {
fullPath = path.resolve(rootDir, relativePath); fullPath = path.resolve(rootDir, relativePath);

View File

@ -2016,6 +2016,22 @@ describe('compiler', function() {
.to.equal(require.resolve('loopback/server/middleware/url-not-found')); .to.equal(require.resolve('loopback/server/middleware/url-not-found'));
}); });
it('supports absolute paths notation', function() {
var middlewarePath =
path.resolve(__dirname, './fixtures/simple-middleware.js');
var routes = {};
routes[middlewarePath] = {};
appdir.writeConfigFileSync('middleware.json', {
'routes': routes,
});
var instructions = boot.compile(appdir.PATH);
expect(instructions.middleware.middleware[0].sourceFile)
.to.equal(path.resolve(appdir.PATH,
middlewarePath));
});
it('supports shorthand notation for relative paths', function() { it('supports shorthand notation for relative paths', function() {
appdir.writeConfigFileSync('middleware.json', { appdir.writeConfigFileSync('middleware.json', {
'routes': { 'routes': {