feat: import api routes globally
This commit is contained in:
@@ -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 🚀');
|
||||
|
||||
Reference in New Issue
Block a user