23 lines
714 B
TypeScript
23 lines
714 B
TypeScript
import { Application } from 'express'
|
|
import { httpLogger } from '#application/logger'
|
|
import fs from 'fs'
|
|
import path from 'path'
|
|
import { getAppPath } from '#application/storage'
|
|
|
|
async function addHttpRoutes(app: Application) {
|
|
const routeFiles = fs.readdirSync(__dirname).filter((file) => {
|
|
return file !== 'index.ts' && file !== 'index.js' && (file.endsWith('.ts') || file.endsWith('.js'))
|
|
})
|
|
|
|
for (const file of routeFiles) {
|
|
const route = await import(getAppPath('http', file))
|
|
// Use the router directly without additional path prefix
|
|
app.use('/', route.default)
|
|
httpLogger.info(`Loaded routes from ${file}`)
|
|
}
|
|
|
|
httpLogger.info('Web routes added')
|
|
}
|
|
|
|
export { addHttpRoutes }
|