-
-
Notifications
You must be signed in to change notification settings - Fork 109
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor app module and add endpoints for dashboard (#944)
* refactor app module and add endpoints for dashboard * Fix test * clean up api * Fix session lookup in validSessionGaurd * Fix postinstall script
- Loading branch information
1 parent
a5f7f6c
commit 4bcba6c
Showing
29 changed files
with
529 additions
and
339 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
prisma/migrations/20231226115334_update_session_log/migration.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
-- AlterTable | ||
ALTER TABLE "SessionLog" ADD COLUMN "is_success" BOOLEAN; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }; |
Oops, something went wrong.