multy-stub/server/root.js

34 lines
916 B
JavaScript
Raw Normal View History

2023-08-01 13:14:02 +03:00
const fs = require('fs')
const path = require('path')
2024-10-16 11:06:23 +03:00
const router = require('express').Router()
const mongoose = require('mongoose')
2024-05-18 11:39:16 +03:00
const pkg = require('../package.json')
2023-08-01 13:14:02 +03:00
2024-10-16 11:06:23 +03:00
require('./utils/mongoose')
2023-08-01 13:14:02 +03:00
const folderPath = path.resolve(__dirname, './routers')
const folders = fs.readdirSync(folderPath)
2024-10-16 11:06:23 +03:00
router.get('/', async (req, res) => {
2024-12-21 00:05:12 +03:00
// throw new Error('check error message')
2024-10-16 11:55:42 +03:00
res.send(`
2024-05-18 11:39:16 +03:00
<h1>multy stub is working v${pkg.version}</h1>
2023-08-01 13:14:02 +03:00
<ul>
${folders.map((f) => `<li>${f}</li>`).join('')}
</ul>
2024-10-16 11:06:23 +03:00
<h2>models</h2>
2024-10-16 11:55:42 +03:00
<ul>${
(await Promise.all(
2024-12-21 00:05:12 +03:00
(await mongoose.modelNames()).map(async (name) => {
2024-10-16 11:55:42 +03:00
const count = await mongoose.model(name).countDocuments()
return `<li>${name} - ${count}</li>`
}
)
)).map(t => t).join(' ')
}</ul>
2023-08-01 13:14:02 +03:00
`)
})
module.exports = router