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 { readFile, readFiles } from "../workflow-management/storage";
|
||||||
import { Router, Request, Response } from 'express';
|
import { Router, Request, Response } from 'express';
|
||||||
import { requireAPIKey } from "../middlewares/api";
|
import { requireAPIKey } from "../middlewares/api";
|
||||||
export const router = Router();
|
const router = Router();
|
||||||
|
|
||||||
const formatRecording = (recordingData: any) => {
|
const formatRecording = (recordingData: any) => {
|
||||||
const recordingMeta = recordingData.recording_meta;
|
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 {
|
try {
|
||||||
const fileContents = await readFiles('./../storage/recordings/');
|
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 {
|
try {
|
||||||
const fileContent = await readFile(`./../storage/recordings/${req.params.fileName}.waw.json`);
|
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 express from 'express';
|
||||||
|
import path from 'path';
|
||||||
import http from 'http';
|
import http from 'http';
|
||||||
import cors from 'cors';
|
import cors from 'cors';
|
||||||
import dotenv from 'dotenv';
|
import dotenv from 'dotenv';
|
||||||
@@ -12,6 +13,7 @@ import cookieParser from 'cookie-parser';
|
|||||||
import csrf from 'csurf';
|
import csrf from 'csurf';
|
||||||
import { SERVER_PORT } from "./constants/config";
|
import { SERVER_PORT } from "./constants/config";
|
||||||
import { Server } from "socket.io";
|
import { Server } from "socket.io";
|
||||||
|
import { readdirSync } from "fs"
|
||||||
|
|
||||||
const csrfProtection = csrf({ cookie: true })
|
const csrfProtection = csrf({ cookie: true })
|
||||||
|
|
||||||
@@ -48,6 +50,16 @@ app.use('/auth', auth);
|
|||||||
app.use('/integration', integration);
|
app.use('/integration', integration);
|
||||||
app.use('/proxy', proxy);
|
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) {
|
app.get('/', function (req, res) {
|
||||||
return res.send('Maxun server started 🚀');
|
return res.send('Maxun server started 🚀');
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -89,7 +89,7 @@ const ApiKeyManager = () => {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<Container>
|
<Container>
|
||||||
<Typography variant="h5">Manage Your API Key</Typography>
|
<Typography variant="h5" sx={{ marginBottom: '20px'}}>Manage Your API Key</Typography>
|
||||||
|
|
||||||
{apiKey ? (
|
{apiKey ? (
|
||||||
<TableContainer component={Paper} sx={{ width: '100%', overflow: 'hidden' }}>
|
<TableContainer component={Paper} sx={{ width: '100%', overflow: 'hidden' }}>
|
||||||
|
|||||||
Reference in New Issue
Block a user