mirror of
https://github.com/directus/directus.git
synced 2026-02-18 19:24:34 -05:00
Co-authored-by: Azri Kahar <42867097+azrikahar@users.noreply.github.com> Co-authored-by: ian <licitdev@gmail.com> Co-authored-by: Rijk van Zanten <rijkvanzanten@me.com>
23 lines
619 B
TypeScript
23 lines
619 B
TypeScript
import { getUrl } from '@common/config';
|
|
import request from 'supertest';
|
|
|
|
export type AllowedRequestMethods = 'get' | 'post' | 'put' | 'patch' | 'delete' | 'search';
|
|
|
|
export type RequestOptions = {
|
|
path: string;
|
|
method: AllowedRequestMethods;
|
|
token: string;
|
|
body?: any;
|
|
};
|
|
|
|
export const PrepareRequest = (vendor: string, requestOptions: RequestOptions) => {
|
|
const req = request(getUrl(vendor))[requestOptions.method](requestOptions.path);
|
|
if (requestOptions.token) {
|
|
req.set('Authorization', `Bearer ${requestOptions.token}`);
|
|
}
|
|
if (requestOptions.body) {
|
|
req.send(requestOptions.body);
|
|
}
|
|
return req;
|
|
};
|