BackendStack21 / restana

Restana is a lightweight and fast Node.js framework for building RESTful APIs.
MIT License
467 stars 27 forks source link

Delete Routes? #80

Closed Syn9673 closed 4 years ago

Syn9673 commented 4 years ago

Is there a way to delete a route?

jkyberneees commented 4 years ago

Hi Alexander, at the moment there are no ways you can unsubscribe a route once registered.

Regards

Syn9673 commented 4 years ago

what if i add a "delete" array and then, if the array contains the url, just send a 404

jkyberneees commented 4 years ago

Of course you add free to add this 404 behaviours on your application by using pre-processing middlewares. Then controlling the availability of routes before it reaches the router itself. I will try to make some time and implement a real delete route functionality inside of 0http and therefore in restana.

Regards

El mié., 15 abr. 2020 a las 10:30, Alexander9673 (notifications@github.com) escribió:

what if i add a "delete" array and then, if the array contains the url, just send a 404

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/jkyberneees/ana/issues/80#issuecomment-613897767, or unsubscribe https://github.com/notifications/unsubscribe-auth/AA7IGXF4NAKSZLYQOXF3RPDRMVWCLANCNFSM4MHV4PDQ .

Syn9673 commented 4 years ago

This is my implementation of it with pug.

if (!fileName)
  fileName = req.url;

if (fileName === '/')
  fileName = core.config.webserver.homepage;

try {
  return core.pug.renderFile(`${core.dir}/contents/${fileName.endsWith('/')
        ? fileName.slice(1)
        : fileName}.pug`, {
    req,
    res
  })
} catch (e) {
  if (e.code === 'ENOENT') {
    if (req.getConfig().allowDebugging)
      console.log(`Removed ${fileName} from routes, with method [GET]`);

    return res.send(404);
  }
}
Syn9673 commented 4 years ago

that is in a function, which is used as a middleware