Answer the question
In order to leave comments, you need to log in
Is it possible to run router in a loop?
The question arose of generating routers in accordance with the list coming from the database, since there are about 220 types of subdomains in the list.
To do this, I decided to use the "express-subdomian" framework.
And wrote the following code:
for (let key in cities) {
let town = ruToLat(key).toLowerCase();
router.get('/', async (req, res) => {
res.render('index', {
title: `Subdomian is: ${key}`,
ifIndex: true,
cities,
key
})
});
router.get('/euro', (req, res) => {
res.render('euro', {
title: 'Subdomian is: ${key} ',
ifEuro: true,
cities,
key
})
});
app.use(subdomain(`${town}`, router));
}
cities
contains an object with the same list. Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question