I'm developing an app using VENoM stack, and in the API I have some middleware like this:
const express = require('express');
const router = express.Router();
require('./routes/orderRoutes')(router);
require('./routes/userRoutes')(router);
require('./routes/ftpRoutes')(router);
module.exports = router;
And I each router has a diferent "path", I mean, to call the API the base URL is https://localhost:8081/api/... And each router starts with a diferent route like /order/... /ftp/... or /user/...
The problem is, that I want to call a GET route from ftpRoutes to orderRoutes like this
router.get('/ftp/importFiles', async function(request, response, next) {
client.ftp.verbose = true
try {
await client.access(ftpTest)
let files = await client.list('/');
files = files.map((file) => { return path.join(downloadsPath, file.name) });
console.log(files);
if (!fs.existsSync(downloadsPath)) {
fs.mkdirSync(downloadsPath, { recursive: true });
}
await client.downloadToDir(downloadsPath, '/');
console.log(files)
request.session.files = files;
} catch (err) {
console.log(err)
}
client.close()
})
And from this route, that is http://localhost:8081/api/ftp/importFiles I want to call to http://localhost:8081/api/order/parseOrder. I've tried using some options like:
- response.redirect('/parseOrder')
- response.redirect('order/parseOrder')
- response.redirect('api/order/parseOrder')
- next('order/parseOrder')
- Etc...
But I cannot make the redirection works fine, so I've thought to change the /ftp/importFiles request to the order router, but I want to keep it separately. Is there any solution to redirect from one router to another router?