Merge pull request #49 from amhsirak/develop
feat: missing server exports for api
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { readFile, readFiles } from "../workflow-management/storage";
|
||||
import { Router, Request, Response } from 'express';
|
||||
import { requireAPIKey } from "../middlewares/api";
|
||||
export const router = Router();
|
||||
const router = Router();
|
||||
|
||||
const formatRecording = (recordingData: any) => {
|
||||
const recordingMeta = recordingData.recording_meta;
|
||||
@@ -27,7 +27,7 @@ const formatRecording = (recordingData: any) => {
|
||||
};
|
||||
|
||||
|
||||
router.get("/api/robots", requireAPIKey, async (req: Request, res: Response) => {
|
||||
router.get("/robots", requireAPIKey, async (req: Request, res: Response) => {
|
||||
try {
|
||||
const fileContents = await readFiles('./../storage/recordings/');
|
||||
|
||||
@@ -80,7 +80,7 @@ const formatRecordingById = (recordingData: any) => {
|
||||
};
|
||||
};
|
||||
|
||||
router.get("/api/robots/:fileName", requireAPIKey, async (req: Request, res: Response) => {
|
||||
router.get("/robots/:fileName", requireAPIKey, async (req: Request, res: Response) => {
|
||||
try {
|
||||
const fileContent = await readFile(`./../storage/recordings/${req.params.fileName}.waw.json`);
|
||||
|
||||
@@ -103,3 +103,5 @@ router.get("/api/robots/:fileName", requireAPIKey, async (req: Request, res: Res
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
export default router;
|
||||
@@ -1,4 +1,5 @@
|
||||
import express from 'express';
|
||||
import path from 'path';
|
||||
import http from 'http';
|
||||
import cors from 'cors';
|
||||
import dotenv from 'dotenv';
|
||||
@@ -12,6 +13,7 @@ import cookieParser from 'cookie-parser';
|
||||
import csrf from 'csurf';
|
||||
import { SERVER_PORT } from "./constants/config";
|
||||
import { Server } from "socket.io";
|
||||
import { readdirSync } from "fs"
|
||||
|
||||
const csrfProtection = csrf({ cookie: true })
|
||||
|
||||
@@ -48,6 +50,16 @@ app.use('/auth', auth);
|
||||
app.use('/integration', integration);
|
||||
app.use('/proxy', proxy);
|
||||
|
||||
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 🚀');
|
||||
});
|
||||
|
||||
@@ -89,7 +89,7 @@ const ApiKeyManager = () => {
|
||||
|
||||
return (
|
||||
<Container>
|
||||
<Typography variant="h5">Manage Your API Key</Typography>
|
||||
<Typography variant="h5" sx={{ marginBottom: '20px'}}>Manage Your API Key</Typography>
|
||||
|
||||
{apiKey ? (
|
||||
<TableContainer component={Paper} sx={{ width: '100%', overflow: 'hidden' }}>
|
||||
|
||||
Reference in New Issue
Block a user