forked from beyondessential/tupaia
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
3008: Switched report-server to using server-boilerplate (beyondessen…
…tial#2866) * 3008: Switched report-server to using server-boilerplate - Moved some types from entity-server to server-boilerplate * 3008: Removed duplicate 'Joined' type from entity-server * 3008: Updated default microService api version to accept any version number * 3008: Switched existing usages of `/fetchReport` endpoint to `GET` * 3008: Fixed up lesmis ReportRoute to return vitals data successfully * 3008: Fixed up ReportRoute in lesmis-server - Vitals will work again as of 3232 * 3008: Added support for POST in FetchReportRoute - Moved TestReportRoute to POST - Reworked types a little * 3008: Updated examples.http * 3008: Fixed permissions bug in FetchReportRoute
- Loading branch information
Showing
32 changed files
with
345 additions
and
309 deletions.
There are no files selected for viewing
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 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 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
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 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,22 @@ | ||
/** | ||
* Tupaia | ||
* Copyright (c) 2017 - 2021 Beyond Essential Systems Pty Ltd | ||
*/ | ||
import { AccessPolicy } from '@tupaia/access-policy'; | ||
import { ReportServerModelRegistry } from '../../types'; | ||
|
||
declare global { | ||
namespace Express { | ||
export interface Request { | ||
accessPolicy: AccessPolicy; | ||
models: ReportServerModelRegistry; | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
ctx: any; | ||
} | ||
|
||
export interface Response { | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
ctx: any; | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -1,51 +1,25 @@ | ||
/** | ||
* Tupaia | ||
* Copyright (c) 2017 - 2020 Beyond Essential Systems Pty Ltd | ||
* Copyright (c) 2017 - 2021 Beyond Essential Systems Pty Ltd | ||
*/ | ||
|
||
import express from 'express'; | ||
import cors from 'cors'; | ||
import bodyParser from 'body-parser'; | ||
import errorHandler from 'api-error-handler'; | ||
import { Authenticator } from '@tupaia/auth'; | ||
import { TupaiaDatabase, ModelRegistry } from '@tupaia/database'; | ||
import { buildBasicBearerAuthMiddleware } from '@tupaia/server-boilerplate'; | ||
|
||
import { addRoutesToApp } from './addRoutesToApp'; | ||
|
||
import { ReportsRequest } from '../types'; | ||
import { MicroServiceApiBuilder, handleWith } from '@tupaia/server-boilerplate'; | ||
import { TupaiaDatabase } from '@tupaia/database'; | ||
import { | ||
FetchReportRequest, | ||
FetchReportRoute, | ||
TestReportRequest, | ||
TestReportRoute, | ||
} from '../routes'; | ||
|
||
/** | ||
* Set up express server with middleware, | ||
* Set up express server | ||
*/ | ||
export function createApp(database: TupaiaDatabase, models: ModelRegistry) { | ||
const app = express(); | ||
|
||
/** | ||
* Add middleware | ||
*/ | ||
app.use(cors()); | ||
app.use(bodyParser.json({ limit: '50mb' })); | ||
app.use(errorHandler()); | ||
|
||
/** | ||
* Add singletons to be attached to req for every route | ||
*/ | ||
app.use((req: ReportsRequest, res, next) => { | ||
req.database = database; | ||
req.models = models; | ||
next(); | ||
}); | ||
|
||
/** | ||
* Attach authentication to each endpoint | ||
*/ | ||
app.use(buildBasicBearerAuthMiddleware('report-server', new Authenticator(models))); | ||
|
||
/** | ||
* Add all routes to the app | ||
*/ | ||
addRoutesToApp(app); | ||
|
||
return app; | ||
export function createApp() { | ||
return new MicroServiceApiBuilder(new TupaiaDatabase()) | ||
.useBasicBearerAuth('report-server') | ||
.get<FetchReportRequest>('fetchReport/:reportCode', handleWith(FetchReportRoute)) | ||
.post<FetchReportRequest>('fetchReport/:reportCode', handleWith(FetchReportRoute)) | ||
.post<TestReportRequest>('testReport', handleWith(TestReportRoute)) | ||
.build(); | ||
} |
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
Oops, something went wrong.