Skip to content

Commit

Permalink
add sitemap
Browse files Browse the repository at this point in the history
  • Loading branch information
VovaStelmashchuk committed Sep 11, 2024
1 parent 89cc279 commit d6691b3
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 1 deletion.
1 change: 0 additions & 1 deletion database/goods.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ function getGoodBySlug(slug) {
);
}


module.exports = {
getGoodBySlug
}
75 changes: 75 additions & 0 deletions features/sitemap/rest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
const express = require('express')

const Database = require('../../database/newclient');
const router = express.Router();

async function getAllCocktailsSlug() {
return Database.collection('cocktails')
.find({}, { slug: 1 })
.toArray();
}

async function getAllToolsSlug() {
return Database.collection('tools')
.find({}, { slug: 1 })
.toArray();
}

async function getAllGoodsSlug() {
return Database.collection('goods')
.find({}, { slug: 1 })
.toArray();
}

async function getAllGlasswareSlug() {
return Database.collection('glassware')
.find({}, { slug: 1 })
.toArray();
}

async function getAllTagsSlug() {
return Database.collection('tags')
.find({}, { slug: 1 })
.toArray();
}

async function getAllTastesSlug() {
return Database.collection('tastes')
.find({}, { slug: 1 })
.toArray();
}

async function getAllAlcoholVolumeSlug() {
return Database.collection('alcoholVolumes')
.find({}, { slug: 1 })
.toArray();
}

router.get('/api/sitemap', async (req, res) => {
const cocktails = (await getAllCocktailsSlug()).map((cocktail) => `cocktails/${cocktail.slug}`);
const goods = (await getAllGoodsSlug()).map((good) => `goods/${good.slug}`);
const tools = (await getAllToolsSlug()).map((tool) => `tools/${tool.slug}`);
const glassware = (await getAllGlasswareSlug()).map((glass) => `glassware/${glass.slug}`);
const tagsFilter = (await getAllTagsSlug()).map((tag) => `tags=${tag.slug}`);
const goodsFilter = (await getAllGoodsSlug()).map((good) => `goods=${good.slug}`);
const toolsFilter = (await getAllToolsSlug()).map((tool) => `tools=${tool.slug}`);
const tastsFilter = (await getAllTastesSlug()).map((tag) => `taste=${tag.slug}`);
const alcoholVolumeFilter = (await getAllAlcoholVolumeSlug()).map((tag) => `alcohol-volume=${tag.slug}`);
const glasswareFilter = (await getAllGlasswareSlug()).map((glass) => `glassware=${glass.slug}`);


const urls = cocktails
.concat(goods)
.concat(tools)
.concat(glassware)
.concat(tagsFilter)
.concat(goodsFilter)
.concat(toolsFilter)
.concat(tastsFilter)
.concat(alcoholVolumeFilter)
.concat(glasswareFilter);

return res.status(200).send(urls);
});

module.exports = router;
2 changes: 2 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const glasswareDetails = require('./features/glassware/rest');
const toolDetails = require('./features/tools/rest');
const goodDetails = require('./features/goods/rest');
const filter = require('./features/filters/rest');
const siteMap = require('./features/sitemap/rest');

const app = express();
const port = process.env.APP_PORT;
Expand All @@ -33,6 +34,7 @@ app.use(
toolDetails,
goodDetails,
filter,
siteMap,
service
);

Expand Down

0 comments on commit d6691b3

Please sign in to comment.