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:
parent
9cb3d0648b
commit
49016b4e66
|
@ -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);
|
||||||
|
|
|
@ -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': {
|
||||||
|
|
Loading…
Reference in New Issue