I'm trying to set up a router.get that is in another folder rather than /routes. When I direct browser to this route, I get "Cannot GET /auth_box" on browser screen. Either you can't so this, or I'm doing something dumb.
app.js:
var index = require('./routes/index');
var auth_box = require('./public/js/download_cs');
app.use('/', index);
app.use('/auth_box', auth_box);
download_cd.js:
var express = require('express');
var app = express();
var router = express.Router();
router.get('/auth_box', function(req, res){
console.log("/auth_box");
});
module.exports = router;
You have the url /auth_box
twice.
When you use a route, the first argument is the default path for that route, so right now the correct URL would be /auth_box/auth_box
In your route, just do
router.get('/', function(req, res){
console.log("/auth_box");
});
As you've already set /auth_box
in app.use('/auth_box', auth_box);
Your download_cd.js
should be like the following. By using, app.use('/auth_box', auth_box);
your are specifying /auth_box
as the base path for all the routes in auth_box
var express = require('express');
var app = express();
var router = express.Router();
router.get('*', function(req, res){ //this matches /auth_box/*
console.log("/auth_box");
});
router.get('/sample', function(req, res){ //this matches /auth_box/sample
console.log("/auth_box/sample");
});
module.exports = router;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With