diff --git a/api/public/swagger.yaml b/api/public/swagger.yaml index d4fb2eb..6a7eafb 100644 --- a/api/public/swagger.yaml +++ b/api/public/swagger.yaml @@ -418,6 +418,25 @@ components: example: /Public/somefolder/some.file type: object additionalProperties: false + InfoResponse: + properties: + mode: + type: string + cors: + type: string + whiteList: + items: + type: string + type: array + protocol: + type: string + required: + - mode + - cors + - whiteList + - protocol + type: object + additionalProperties: false securitySchemes: bearerAuth: type: http @@ -1240,10 +1259,31 @@ paths: application/json: schema: $ref: '#/components/schemas/ExecuteReturnJsonPayload' + /SASjsApi/info: + get: + operationId: Info + responses: + '200': + description: Ok + content: + application/json: + schema: + $ref: '#/components/schemas/InfoResponse' + examples: + 'Example 1': + value: {mode: desktop, cors: enable, whiteList: ['http://example.com', 'http://example2.com'], protocol: http} + summary: 'Get server info (mode, cors, whiteList, protocol).' + tags: + - Info + security: [] + parameters: [] servers: - url: / tags: + - + name: Info + description: 'Get Server Info' - name: Session description: 'Get Session information' diff --git a/api/src/controllers/index.ts b/api/src/controllers/index.ts index d2efa88..05e8b84 100644 --- a/api/src/controllers/index.ts +++ b/api/src/controllers/index.ts @@ -6,3 +6,4 @@ export * from './group' export * from './session' export * from './stp' export * from './user' +export * from './info' diff --git a/api/src/controllers/info.ts b/api/src/controllers/info.ts new file mode 100644 index 0000000..0db2626 --- /dev/null +++ b/api/src/controllers/info.ts @@ -0,0 +1,37 @@ +import express from 'express' +import { Request, Security, Route, Tags, Example, Get } from 'tsoa' + +export interface InfoResponse { + mode: string + cors: string + whiteList: string[] + protocol: string +} + +@Route('SASjsApi/info') +@Tags('Info') +export class InfoController { + /** + * @summary Get server info (mode, cors, whiteList, protocol). + * + */ + @Example({ + mode: 'desktop', + cors: 'enable', + whiteList: ['http://example.com', 'http://example2.com'], + protocol: 'http' + }) + @Get('/') + public info(): InfoResponse { + const response = { + mode: process.env.MODE ?? 'desktop', + cors: + process.env.CORS ?? process.env.MODE === 'server' + ? 'disable' + : 'enable', + whiteList: process.env.WHITELIST?.split(' ') ?? [], + protocol: process.env.PROTOCOL ?? 'http' + } + return response + } +} diff --git a/api/src/routes/api/index.ts b/api/src/routes/api/index.ts index e21022d..7b249a9 100644 --- a/api/src/routes/api/index.ts +++ b/api/src/routes/api/index.ts @@ -9,6 +9,7 @@ import { verifyAdmin } from '../../middlewares' +import infoRouter from './info' import driveRouter from './drive' import stpRouter from './stp' import codeRouter from './code' @@ -20,6 +21,7 @@ import sessionRouter from './session' const router = express.Router() +router.use('/info', infoRouter) router.use('/session', desktopUsername, authenticateAccessToken, sessionRouter) router.use('/auth', desktopRestrict, authRouter) router.use( diff --git a/api/src/routes/api/info.ts b/api/src/routes/api/info.ts new file mode 100644 index 0000000..fb71f66 --- /dev/null +++ b/api/src/routes/api/info.ts @@ -0,0 +1,16 @@ +import express from 'express' +import { InfoController } from '../../controllers' + +const infoRouter = express.Router() + +infoRouter.get('/', async (req, res) => { + const controller = new InfoController() + try { + const response = controller.info() + res.send(response) + } catch (err: any) { + res.status(403).send(err.toString()) + } +}) + +export default infoRouter diff --git a/api/src/routes/api/spec/info.spec.ts b/api/src/routes/api/spec/info.spec.ts new file mode 100644 index 0000000..2f86c66 --- /dev/null +++ b/api/src/routes/api/spec/info.spec.ts @@ -0,0 +1,14 @@ +import { Express } from 'express' +import request from 'supertest' +import appPromise from '../../../app' + +let app: Express + +describe('Info', () => { + it('should should return configured information of the server instance', async () => { + await appPromise.then((_app) => { + app = _app + }) + request(app).get('/SASjsApi/info').expect(200) + }) +}) diff --git a/api/tsoa.json b/api/tsoa.json index 8fe396f..61c1390 100644 --- a/api/tsoa.json +++ b/api/tsoa.json @@ -11,6 +11,10 @@ } }, "tags": [ + { + "name": "Info", + "description": "Get Server Info" + }, { "name": "Session", "description": "Get Session information"