Skip to content

Commit

Permalink
refactor app module and add endpoints for dashboard (#944)
Browse files Browse the repository at this point in the history
* refactor app module and add endpoints for dashboard

* Fix test

* clean up api

* Fix session lookup in validSessionGaurd

* Fix postinstall script
  • Loading branch information
sudharsan-selvaraj authored Dec 27, 2023
1 parent a5f7f6c commit 4bcba6c
Show file tree
Hide file tree
Showing 29 changed files with 529 additions and 339 deletions.
39 changes: 39 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"install-driver": "export APPIUM_HOME=/tmp/some-temp-dir && appium driver install xcuitest",
"reinstall-plugin": "export APPIUM_HOME=/tmp/some-temp-dir && npm run appium-home && (appium plugin uninstall device-farm || exit 0) && npm run install-plugin",
"run-server": "export APPIUM_HOME=/tmp/some-temp-dir && appium server -ka 800 --use-plugins=device-farm,appium-dashboard -pa /wd/hub --plugin-device-farm-platform=ios --plugin-device-farm-max-sessions=8",
"run-db-migration": "((path-exists lib/src/scripts/initialize-database.js || npm run build) && node lib/src/scripts/initialize-database.js) || exit 0",
"run-db-migration": "path-exists lib/src/scripts/initialize-database.js && node lib/src/scripts/initialize-database.js || ts-node src/scripts/initialize-database.ts",
"generate-migration": "ts-node src/scripts/generate-database-migration.ts",
"postinstall": "npm run run-db-migration"
},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- AlterTable
ALTER TABLE "SessionLog" ADD COLUMN "is_success" BOOLEAN;
1 change: 1 addition & 0 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ model SessionLog {
body String?
response String
screenshot String?
is_success Boolean?
// Timestamps
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
Expand Down
1 change: 1 addition & 0 deletions src/CapabilityManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export enum DEVICE_FARM_CAPABILITIES {
VIDEO_RECORDING = 'record_video',
VIDEO_RESOLUTION = 'video_resolution',
LIVE_VIDEO = 'live_video',
SCREENSHOT_ON_FAILURE = 'screenshot_on_failure',

DEVICE_FARM_OPTIONS = 'df:options',
}
Expand Down
210 changes: 0 additions & 210 deletions src/app.ts

This file was deleted.

65 changes: 65 additions & 0 deletions src/app/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import express from 'express';
import path from 'path';

import { getCLIArgs } from '../data-service/pluginArgs';
import cors from 'cors';
import AsyncLock from 'async-lock';
import axios from 'axios';
import { config } from '../config';
import _ from 'lodash';

import DashboardRouter from './routers/dashboard';
import GridRouter from './routers/grid';

let dashboardPluginUrl: any = null;

const ASYNC_LOCK = new AsyncLock();

const router = express.Router(),
apiRouter = express.Router(),
staticFilesRouter = express.Router();

router.use(cors());
apiRouter.use(cors());
staticFilesRouter.use(cors());

/**
* Middleware to check if the appium-dashboard plugin is installed
* If the plugin is runnig, then we should enable the react app to
* open the dashboard link upon clicking the device card in the UI.
*/

//TODO: Remove the middleware after integrating with dashbaod
apiRouter.use(async (req, res, next) => {
await ASYNC_LOCK.acquire('dashboard-plugin-check', async () => {
if (dashboardPluginUrl == null) {
const pingurl = `${req.protocol}://${req.get('host')}/dashboard/api/ping`;
try {
const response: any = await axios.get(pingurl);
if (response.data['pong']) {
dashboardPluginUrl = `${req.protocol}://${req.get('host')}/dashboard`;
} else {
dashboardPluginUrl = '';
}
} catch (err) {
dashboardPluginUrl = '';
}
}
});
(req as any)['dashboard-plugin-url'] = dashboardPluginUrl;
return next();
});

apiRouter.get('/cliArgs', async (req, res) => {
res.json(await getCLIArgs());
});

staticFilesRouter.use(express.static(path.join(__dirname, '..', '..', 'public')));
router.use('/api', apiRouter);
router.use('/assets', express.static(config.sessionAssetsPath));
router.use(staticFilesRouter);

DashboardRouter.register(apiRouter);
GridRouter.register(apiRouter);

export { router };
Loading

0 comments on commit 4bcba6c

Please sign in to comment.