Monday 12 June 2017

NodeJs app routing depending on request path

I will share the code directly

in webserver.js

var objApiServer = require('./node_scripts/ApiServer');
app.use('/APICalls', objApiServer);

//FUNCTION 1
app.get('/GetDbData', function(req, res) {
res.status(200).send("Sample Data");
});

and in ApiServer.js

module.exports = function (router, request) {

//FUNCTION 2
router.get('/GetDbData', function (req, res) {
/* SAMPLE CODE GOES HERE */
});

}

on mysite.domain/APICall/GetDbData the function2 in ApiServer.js is working

and on mysite.domain/GetDbData also Function2 is working instead of Function1..

Plz clarify why it happens and is there any to restrict that. im new to NodeJs

in real case i dont want mysite.domain/GetDbData to work on any function i jst created function1 to stop function2 from execution ...



via DrVishnu

No comments:

Post a Comment