-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6970687
commit 4a90977
Showing
13 changed files
with
222 additions
and
195 deletions.
There are no files selected for viewing
Empty file.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,40 @@ | ||
import express, { Express, Request, Response } from 'express'; | ||
import dotenv from 'dotenv'; | ||
import bodyParser from 'body-parser'; | ||
import { logRequestBatchHandler, logRequestSingleHandler } from "./api/log-request" | ||
import { AppDataSource } from './data-source'; | ||
import express, { Express, Request, Response } from "express"; | ||
import dotenv from "dotenv"; | ||
import bodyParser from "body-parser"; | ||
import { | ||
logRequestBatchHandler, | ||
logRequestSingleHandler, | ||
} from "./api/log-request"; | ||
import { AppDataSource } from "./data-source"; | ||
|
||
dotenv.config(); | ||
|
||
const app: Express = express(); | ||
const port = process.env.PORT || 8080; | ||
|
||
app.use(bodyParser.json()) | ||
app.use(bodyParser.json()); | ||
|
||
app.get('/', (req: Request, res: Response) => { | ||
res.send('OK'); | ||
app.get("/", (req: Request, res: Response) => { | ||
res.send("OK"); | ||
}); | ||
|
||
app.post('/log-request/single', logRequestSingleHandler) | ||
app.post('/log-request/batch', logRequestBatchHandler) | ||
app.post("/log-request/single", logRequestSingleHandler); | ||
app.post("/log-request/batch", logRequestBatchHandler); | ||
|
||
const main = async () => { | ||
try { | ||
const datasource = await AppDataSource.initialize(); | ||
console.log( | ||
`Is AppDataSource Initialized? ${ | ||
datasource.isInitialized ? "Yes" : "No" | ||
}`, | ||
) | ||
`Is AppDataSource Initialized? ${datasource.isInitialized ? "Yes" : "No"}` | ||
); | ||
app.listen(port, () => { | ||
console.log(`⚡️[server]: Server is running at http://localhost:${port}`); | ||
}); | ||
} catch (err) { | ||
console.error(`CatchBlockInsideMain: ${err}`) | ||
console.error(`CatchBlockInsideMain: ${err}`); | ||
} | ||
} | ||
}; | ||
|
||
main().catch(err => { | ||
console.error(`Error in main try block: ${err}`) | ||
}) | ||
main().catch((err) => { | ||
console.error(`Error in main try block: ${err}`); | ||
}); |
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,46 +1,51 @@ | ||
import { FindManyOptions, FindOptionsWhere } from "typeorm"; | ||
import { GetEndpointParams } from "../../types"; | ||
import { AppDataSource } from "../../data-source" | ||
import { AppDataSource } from "../../data-source"; | ||
import { ApiEndpoint } from "../../../models"; | ||
|
||
export class GetEndpointsService { | ||
static async getEndpoints(getEndpointParams: GetEndpointParams): Promise<ApiEndpoint[]> { | ||
static async getEndpoints( | ||
getEndpointParams: GetEndpointParams | ||
): Promise<ApiEndpoint[]> { | ||
try { | ||
const apiEndpointRepository = AppDataSource.getRepository(ApiEndpoint); | ||
let whereConditions: FindOptionsWhere<ApiEndpoint> = {} | ||
let paginationParams: FindManyOptions<ApiEndpoint> = {} | ||
let whereConditions: FindOptionsWhere<ApiEndpoint> = {}; | ||
let paginationParams: FindManyOptions<ApiEndpoint> = {}; | ||
if (getEndpointParams?.environment) { | ||
whereConditions = { | ||
...whereConditions, | ||
environment: getEndpointParams.environment | ||
} | ||
environment: getEndpointParams.environment, | ||
}; | ||
} | ||
if (getEndpointParams?.host) { | ||
whereConditions = { | ||
...whereConditions, | ||
host: getEndpointParams.host | ||
} | ||
host: getEndpointParams.host, | ||
}; | ||
} | ||
if (getEndpointParams?.offset) { | ||
paginationParams = { | ||
...paginationParams, | ||
skip: getEndpointParams.offset | ||
} | ||
skip: getEndpointParams.offset, | ||
}; | ||
} | ||
if (getEndpointParams?.limit) { | ||
paginationParams = { | ||
...paginationParams, | ||
take: getEndpointParams.limit | ||
} | ||
take: getEndpointParams.limit, | ||
}; | ||
} | ||
|
||
const endpoints = await apiEndpointRepository.find({ where: whereConditions, ...paginationParams }) | ||
|
||
const endpoints = await apiEndpointRepository.find({ | ||
where: whereConditions, | ||
...paginationParams, | ||
}); | ||
|
||
// TODO: Calculate risk score for endpoints and if risk score param present, only return those that meet | ||
|
||
return endpoints | ||
return endpoints; | ||
} catch (err) { | ||
console.error(`Error in Get Endpoints service: ${err}`) | ||
console.error(`Error in Get Endpoints service: ${err}`); | ||
} | ||
} | ||
} | ||
} |
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.