Skip to content

Commit

Permalink
Merge pull request #114 from sima-land/38-examples-bun
Browse files Browse the repository at this point in the history
  • Loading branch information
krutoo committed Mar 11, 2024
2 parents e1379f0 + c86c9cf commit 6e31158
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 45 deletions.
32 changes: 16 additions & 16 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,15 @@
"dotenv": "^16.3.1",
"express": "^4.18.2",
"jsesc": "^3.0.2",
"middleware-axios": "^2.1.5",
"middleware-axios": "^2.1.6",
"pino": "^8.14.1",
"pino-pretty": "^9.1.1",
"prom-client": "^14.2.0",
"webpack": "^5.82.0"
},
"peerDependencies": {
"@reduxjs/toolkit": "^1.9.5",
"axios": "^1.4.0",
"axios": "^1.6.7",
"react": "^17.0 || ^18.0",
"react-dom": "^17.0 || ^18.0",
"react-redux": "^8.0.5",
Expand Down
6 changes: 3 additions & 3 deletions src/preset/isomorphic/providers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,13 @@ export function provideAxiosFactory(resolve: Resolve) {
const middleware = resolve(KnownToken.Axios.middleware);

return (config: CreateAxiosDefaults = {}) => {
const client = create(config as any); // @todo убрать as any
const instance = create(config);

for (const item of middleware) {
client.use(item);
instance.use(item);
}

return client;
return instance;
};
}

Expand Down
9 changes: 6 additions & 3 deletions src/preset/node/utils/axios-tracing-middleware.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { AxiosDefaults, AxiosRequestConfig } from 'axios';
import type { AxiosInstance, AxiosRequestConfig, HeadersDefaults } from 'axios';
import type { Middleware } from 'middleware-axios';
import { Context, Tracer, SpanStatusCode } from '@opentelemetry/api';
import { SemanticAttributes } from '@opentelemetry/semantic-conventions';
Expand All @@ -24,8 +24,11 @@ export function axiosTracingMiddleware(tracer: Tracer, rootContext: Context): Mi
...config.params,
}),
'request.headers': JSON.stringify({
...defaults.headers[method.toLowerCase() as 'get'],
// @todo непонятно как доставать заголовки из defaults потому что там на одном уровне заголовки и таблицы заголовков
...defaults.headers.common,
...defaults.headers[method.toLowerCase() as keyof HeadersDefaults],
...config.headers,
// @todo возможно стоит убрать cookie/Cookie
}),

// если нашли id - добавляем в теги
Expand Down Expand Up @@ -59,7 +62,7 @@ export function axiosTracingMiddleware(tracer: Tracer, rootContext: Context): Mi
*/
export function getRequestInfo(
config: AxiosRequestConfig,
defaults: AxiosDefaults,
defaults: AxiosInstance['defaults'],
): {
method: string;
url: string;
Expand Down
34 changes: 17 additions & 17 deletions src/utils/axios/middleware/__test__/cookie.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AxiosDefaults, InternalAxiosRequestConfig } from 'axios';
import { AxiosHeaders, AxiosInstance, InternalAxiosRequestConfig } from 'axios';
import { Next } from 'middleware-axios';
import { cookieMiddleware } from '../cookie';
import { createCookieStore } from '../../../../http';
Expand All @@ -23,15 +23,15 @@ describe('cookieMiddleware', () => {
headers: {},
}),
);
const defaults: AxiosDefaults = {
const defaults: AxiosInstance['defaults'] = {
headers: {
get: {},
post: {},
put: {},
delete: {},
patch: {},
common: {},
head: {},
get: new AxiosHeaders(),
post: new AxiosHeaders(),
put: new AxiosHeaders(),
delete: new AxiosHeaders(),
patch: new AxiosHeaders(),
common: new AxiosHeaders(),
head: new AxiosHeaders(),
},
};

Expand Down Expand Up @@ -73,15 +73,15 @@ describe('cookieMiddleware', () => {
} as any,
}),
);
const defaults: AxiosDefaults = {
const defaults: AxiosInstance['defaults'] = {
headers: {
get: {},
post: {},
put: {},
delete: {},
patch: {},
common: {},
head: {},
get: new AxiosHeaders(),
post: new AxiosHeaders(),
put: new AxiosHeaders(),
delete: new AxiosHeaders(),
patch: new AxiosHeaders(),
common: new AxiosHeaders(),
head: new AxiosHeaders(),
},
};

Expand Down
8 changes: 4 additions & 4 deletions src/utils/axios/middleware/__test__/log.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AxiosRequestConfig, AxiosDefaults, AxiosResponse } from 'axios';
import { AxiosRequestConfig, AxiosResponse, AxiosInstance } from 'axios';
import { Next } from 'middleware-axios';
import { logMiddleware, LogMiddlewareHandler } from '../log';

Expand Down Expand Up @@ -31,7 +31,7 @@ describe('logMiddleware', () => {
it('should works properly without error', async () => {
const config: AxiosRequestConfig<any> = {};

const defaults: AxiosDefaults<any> = {
const defaults: AxiosInstance['defaults'] = {
headers: {} as any,
baseURL: 'https://sima.com/',
};
Expand Down Expand Up @@ -62,7 +62,7 @@ describe('logMiddleware', () => {
it('should works properly with error', async () => {
const config: AxiosRequestConfig<any> = {};

const defaults: AxiosDefaults<any> = {
const defaults: AxiosInstance['defaults'] = {
headers: {} as any,
baseURL: 'https://sima.com/',
};
Expand All @@ -87,7 +87,7 @@ describe('logMiddleware', () => {
it('should handle handler factory', async () => {
const config: AxiosRequestConfig<any> = {};

const defaults: AxiosDefaults<any> = {
const defaults: AxiosInstance['defaults'] = {
headers: {} as any,
baseURL: 'https://sima.com/',
};
Expand Down

0 comments on commit 6e31158

Please sign in to comment.