Skip to content

Query regarding endpoint generation in subfolders #934

@ZaLiTHkA

Description

@ZaLiTHkA

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..?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions