Skip to content

Query regarding endpoint generation in subfolders #934

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
ZaLiTHkA opened this issue Apr 16, 2015 · 2 comments
Closed

Query regarding endpoint generation in subfolders #934

ZaLiTHkA opened this issue Apr 16, 2015 · 2 comments

Comments

@ZaLiTHkA
Copy link

Not entirely sure if I'm doing something silly here or if this is something that should be handled differently in the generator. This is mostly just for my enlightenment, perhaps it will be for others as well, but either way this is bugging me.

For the record, I'm in Windows 8.1 using Bash from Cygwin. If I type folder paths myself, I have a bit of a *nix mentality, so this allows me use / as path separators in Windows.

Firstly, to explain what I was trying to achieve.. I wanted an API endpoint of [host]:[port]/api/company/details (with nothing at /api/company directly), but my first attempt failed horribly:

$ yo angular-fullstack:endpoint company/detail
? What will the url of your endpoint to be? /api/company/details
   create server\api\company\detail\index.js
   create server\api\company\detail\company\detail.controller.js
   create server\api\company\detail\company\detail.model.js
   create server\api\company\detail\company\detail.socket.js
   create server\api\company\detail\company\detail.spec.js

First problem here: folder structure goes haywire.

Checking the contents of routes.js, I see require('./api/company/detail') as one would expect. Checking api/company/detail/index.js, I see require('./company/detail.controller'), also just as one would expect.

This is where the real problem starts though.. The variable used throughout the endoint is now company/detail, so I end up with code such as:

// Get a single company/detail
exports.show = function(req, res) {
  CompanyDetail.findById(req.params.id, function (err, company/detail) {
    if(err) { return handleError(res, err); }
    if(!company/detail) { return res.send(404); }
    return res.json(company/detail);
  });
};

Quite obviously, this doesn't run.. So in the end I generated the endpoint as simply detail and set the URL to /api/company/detail. From my frontend, I call the info by requesting "company details", so that part is pretty logical. It's just the folder structure that annoys me now.

I know I can simply move files and update paths to get around this, but is there a better way to nest endpoints using the generator itself? Or could someone perhaps give me a reason to not do this..?

@kingcody
Copy link
Member

closed by #1122

@ZaLiTHkA
Copy link
Author

ZaLiTHkA commented Oct 6, 2015

First off, my apologies for taking so long to respond to my initial report.. I was keeping an eye out for the 2.3.0 milestone, but in the meantime it looks like plans changed and a volcano or two erupted and life itself happened, so I simply didn't get around to it.

I've just checked with the latest (3.0.0-rc8), using the exact same steps as my initial report: all files were created correctly and all require(...) references in the new endpoint are correct. Without modifying any code, I checked my new blank endpoint and got a HTTP 200 response, so it looks like everything is good here now. Thanks for sorting this one out. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants