feat: import api routes globally

This commit is contained in:
karishmas6
2024-10-03 17:19:20 +05:30
parent 05ebe1d7ad
commit 8b6c807642

View File

@@ -1,4 +1,5 @@
import express from 'express';
import path from 'path';
import http from 'http';
import cors from 'cors';
import dotenv from 'dotenv';
@@ -49,7 +50,15 @@ app.use('/auth', auth);
app.use('/integration', integration);
app.use('/proxy', proxy);
readdirSync('./api').map(r => app.use('/api', require(`./api/${r}`)))
readdirSync(path.join(__dirname, 'api')).forEach((r) => {
const route = require(path.join(__dirname, 'api', r));
const router = route.default || route; // Use .default if available, fallback to route
if (typeof router === 'function') {
app.use('/api', router); // Use the default export or named router
} else {
console.error(`Error: ${r} does not export a valid router`);
}
});
app.get('/', function (req, res) {
return res.send('Maxun server started 🚀');