forked from asyncapi/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbundle.controller.ts
More file actions
47 lines (39 loc) · 1.23 KB
/
Copy pathbundle.controller.ts
File metadata and controls
47 lines (39 loc) · 1.23 KB
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import { NextFunction, Request, Response, Router } from 'express';
import bundler from '@asyncapi/bundler';
import { validationMiddleware } from '../middlewares/validation.middleware';
import { ProblemException } from '../exceptions/problem.exception';
import { Controller } from '@/interfaces';
export class BundleController implements Controller {
public basepath = '/bundle';
private async bundle(req: Request, res: Response, next: NextFunction) {
const asyncapis: Array<string> = req.body.asyncapis;
const base = req.body.base;
try {
const document = await bundler(asyncapis, { base });
const bundled = document.json();
res.status(200).json({ bundled });
} catch (err) {
return next(
new ProblemException({
type: 'internal-bundler-error',
title: 'Internal Bundler error',
status: 500,
detail: (err as Error).message,
}),
);
}
}
public async boot(): Promise<Router> {
const router = Router();
router.post(
this.basepath,
await validationMiddleware({
path: this.basepath,
method: 'post',
documents: ['asyncapis', 'base'],
}),
this.bundle.bind(this),
);
return router;
}
}