-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathBlueprintAdditions.ts
27 lines (23 loc) · 1 KB
/
BlueprintAdditions.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import express from 'express';
import _ from 'lodash';
import type { AxiosRequestHeaders } from 'axios';
import { getHeadersWithAuthenticationTokenFromRequest } from '../utils';
import * as ManagerHandler from '../handler/ManagerHandler';
import { requestAndForwardResponse } from '../handler/RequestHandler';
const router = express.Router();
router.get('/image/:tenantName/:blueprintId', (req, res, next) => {
const { blueprintId, tenantName } = req.params;
const blueprintIconUrl = `${ManagerHandler.getManagerUrl()}/resources/blueprints/${tenantName}/${blueprintId}/icon.png`;
const options = {
headers: getHeadersWithAuthenticationTokenFromRequest(req, req.headers as AxiosRequestHeaders)
};
ManagerHandler.setManagerSpecificOptions(options, 'get');
requestAndForwardResponse(blueprintIconUrl, res, options).catch(err => {
if (err.response?.status === 304) {
res.status(304).end();
} else {
next(err);
}
});
});
export default router;