I am using Express.js and I am having trouble routing to a middleware function that I want to get called. I have app.js, userauth.routes.js, and index.js. If the url starts with /user/, it is intended to go to a function in userauth.routes.js to verify the session. Afterwards, it is supposed to be routed to index.js. Unfortunately, it seems like the validation part is completely skipped over.
app.js:
var userauthRouter = require('./routes/userauth.routes.js');
var indexRouter = require('./routes');
app.use('/user/', userauthRouter);
app.use('/', indexRouter);
userauth.routes.js:
var express = require('express');
var router = express.Router();
router.get("/*", function(req, res, next){
console.log("user authentication");
next();
});
module.exports = router;
index.js
var express = require('express');
var router = express.Router();
/* GET home page. */
router.get('/*', function(req, res, next) {
res.sendFile(path.join(__dirname, 'dist', 'index.html'));
});
module.exports = router;
At the moment, I should see user authentication in the output but I see nothing.