-
-
Notifications
You must be signed in to change notification settings - Fork 22.5k
Closed
Description
I am using a router (express.Router - called testrouter in the code here) added to main app (express) and i add subrouter (express.Router) to this router/testrouter with a function just before it to test if request is from specific referer, but the subrouter is never skipped!
const express = require('express');
const http = require('http');
const httpport = process.env.PORT || 80; //http
app = express();
var testrouter = express.Router();
app.use(testrouter);
var subrouter = express.Router();
var subrouterRoute = '/blabla'
testrouter.use(subrouterRoute,
function(req, res, next){
console.log('trying to go into subrouter');
if (req.headers.referer) {console.log('going', typeof req.headers.referer), next();}
else {console.log('not going', typeof req.headers.referer); next('route');}
},
subrouter,
function(req,res,next){
console.log('gone out of subrouter');
next();
}
);
subrouter.use(function(req,res,next){
console.log('IN SUBROUTER');
next();
})
http
.createServer(app)
.listen(httpport, function(){
console.log("server http listened @ : ", this.address());
});if i request /blabla directly, there is no referer so it is undefined... but though, the console logs the following:
trying to go into subrouter
not going undefined (this is the referer)
IN SUBROUTER
gone out of subrouter
Reactions are currently unavailable