colthreepv / express-raml-store

Express 4 Router to serve mulesoft's api-designer, and save your work on filesystem
MIT License
27 stars 10 forks source link

Static api-designer path issue npm v3 #6

Closed OliverFischer closed 8 years ago

OliverFischer commented 8 years ago

Hi,

if we host the express-raml-store as part of our application and using npm v3 the styles and scripts of the api designer are not found. While the index file is delivered with respect to the npm version, the api-designer resources aren't.

As shown here :

try { // support both npm 2.x and 3.x
  // npm 2.x subdir
  indexFile = fs.readFileSync(path.join(__dirname, 'node_modules/api-designer/dist/index.html'), 'utf8');
} catch (err) {
  // npm 3.x brother dir
  indexFile = fs.readFileSync(path.join(__dirname, '..', '/api-designer/dist/index.html'), 'utf8');
}

in contrast to :

res.sendFile(requestedFile, { root: path.join(__dirname, 'node_modules/api-designer/dist') }, function (err) {
    if (err && err.code === 'ENOENT') return res.sendStatus(404);
    if (err) return next(err);
  });

We had to modify the path to walk one directory up

res.sendFile(requestedFile, { root: path.join(__dirname, '../api-designer/dist') }, function 

to make it work. Is this intended?

Greetings Olli

arcesino commented 8 years ago

@OliverFischer Agree with your reasoning. I don't think that was the intended behavior, seems to me more as an incomplete attempt to support both npm versions.

I have created PR #7 which fixes this issue. I have tested it with both, npm 2.x & 3.x, and in both cases the fix worked.

Hope it helps!

Best, Nacho

colthreepv commented 8 years ago

I have been absent :cry: will pick this up soon and review my work a little. Thanks for your contributions, if you wish to be collaborators you're welcome as well

OliverFischer commented 8 years ago

Hi, is it possible to accept the PR from @arcesino ? It looks good...

colthreepv commented 8 years ago

merged #7 as suggested, let me know if the problem is fixed as expected