chore: Use get app helper to get application data
This commit is contained in:
@@ -2,10 +2,10 @@ import express, { Application } from 'express';
|
||||
import App from '../models/app';
|
||||
|
||||
const appAssetsHandler = async (app: Application) => {
|
||||
const appNames = App.list;
|
||||
const appList = await App.findAll();
|
||||
|
||||
appNames.forEach(appName => {
|
||||
const svgPath = `${__dirname}/../apps/${appName}/assets/favicon.svg`;
|
||||
appList.forEach((appItem) => {
|
||||
const svgPath = `${__dirname}/../apps/${appItem.name}/assets/favicon.svg`;
|
||||
const staticFileHandlerOptions = {
|
||||
/**
|
||||
* Disabling fallthrough is important to respond with HTTP 404.
|
||||
@@ -15,11 +15,8 @@ const appAssetsHandler = async (app: Application) => {
|
||||
};
|
||||
const staticFileHandler = express.static(svgPath, staticFileHandlerOptions);
|
||||
|
||||
app.use(
|
||||
`/apps/${appName}/assets/favicon.svg`,
|
||||
staticFileHandler
|
||||
)
|
||||
})
|
||||
}
|
||||
app.use(`/apps/${appItem.name}/assets/favicon.svg`, staticFileHandler);
|
||||
});
|
||||
};
|
||||
|
||||
export default appAssetsHandler;
|
||||
|
@@ -1,12 +1,20 @@
|
||||
import type { IApp } from '@automatisch/types';
|
||||
import appConfig from '../config/app';
|
||||
|
||||
const appInfoConverter = (rawAppData: string) => {
|
||||
let computedRawData = rawAppData.replace('{BASE_URL}', appConfig.baseUrl);
|
||||
computedRawData = computedRawData.replace('{WEB_APP_URL}', appConfig.webAppUrl);
|
||||
const appInfoConverter = (rawAppData: IApp) => {
|
||||
const stringifiedRawAppData = JSON.stringify(rawAppData);
|
||||
|
||||
const computedJSONData: IApp = JSON.parse(computedRawData)
|
||||
let computedRawData = stringifiedRawAppData.replace(
|
||||
'{BASE_URL}',
|
||||
appConfig.baseUrl
|
||||
);
|
||||
computedRawData = computedRawData.replace(
|
||||
'{WEB_APP_URL}',
|
||||
appConfig.webAppUrl
|
||||
);
|
||||
|
||||
const computedJSONData: IApp = JSON.parse(computedRawData);
|
||||
return computedJSONData;
|
||||
}
|
||||
};
|
||||
|
||||
export default appInfoConverter;
|
||||
|
67
packages/backend/src/helpers/get-app.ts
Normal file
67
packages/backend/src/helpers/get-app.ts
Normal file
@@ -0,0 +1,67 @@
|
||||
import fs from 'fs';
|
||||
import { join } from 'path';
|
||||
import { IApp } from '@automatisch/types';
|
||||
|
||||
const folderPath = join(__dirname, '../apps');
|
||||
|
||||
const getApp = async (appKey: string) => {
|
||||
const appData: IApp = (await import(`../apps/${appKey}`)).default;
|
||||
|
||||
let rawAuthData = (await import(`../apps/${appKey}/auth/index.ts`)).default;
|
||||
|
||||
rawAuthData = Object.fromEntries(
|
||||
Object.entries(rawAuthData).filter(
|
||||
([key]) => typeof rawAuthData[key] !== 'function'
|
||||
)
|
||||
);
|
||||
|
||||
appData.auth = rawAuthData;
|
||||
|
||||
appData.triggers = [];
|
||||
|
||||
const triggersPath = join(folderPath, appKey, 'triggers');
|
||||
|
||||
if (fs.existsSync(triggersPath)) {
|
||||
const triggersFolder = fs.readdirSync(join(folderPath, appKey, 'triggers'));
|
||||
|
||||
for (const triggerName of triggersFolder) {
|
||||
let rawTriggerData = (
|
||||
await import(`../apps/${appKey}/triggers/${triggerName}/index.ts`)
|
||||
).default;
|
||||
|
||||
rawTriggerData = Object.fromEntries(
|
||||
Object.entries(rawTriggerData).filter(
|
||||
([key]) => typeof rawTriggerData[key] !== 'function'
|
||||
)
|
||||
);
|
||||
|
||||
appData.triggers.push(rawTriggerData);
|
||||
}
|
||||
}
|
||||
|
||||
appData.actions = [];
|
||||
|
||||
const actionsPath = join(folderPath, appKey, 'actions');
|
||||
|
||||
if (fs.existsSync(actionsPath)) {
|
||||
const actionsFolder = fs.readdirSync(join(folderPath, appKey, 'actions'));
|
||||
|
||||
for await (const actionName of actionsFolder) {
|
||||
let rawActionData = (
|
||||
await import(`../apps/${appKey}/actions/${actionName}/index.ts`)
|
||||
).default;
|
||||
|
||||
rawActionData = Object.fromEntries(
|
||||
Object.entries(rawActionData).filter(
|
||||
([key]) => typeof rawActionData[key] !== 'function'
|
||||
)
|
||||
);
|
||||
|
||||
appData.actions.push(rawActionData);
|
||||
}
|
||||
}
|
||||
|
||||
return appData;
|
||||
};
|
||||
|
||||
export default getApp;
|
Reference in New Issue
Block a user