-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- preset/web: модуль провайдеров разбит на отдельные модули по провайдерам (patch)
- Loading branch information
Showing
8 changed files
with
145 additions
and
139 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { Resolve } from '../../../di'; | ||
import { KnownToken } from '../../../tokens'; | ||
import { HttpStatus } from '../../isomorphic/utils/http-status'; | ||
import { logMiddleware } from '../../../utils/axios'; | ||
|
||
/** | ||
* Провайдер фабрики http-клиентов. | ||
* @param resolve Функция для получения зависимости по токену. | ||
* @return Фабрика. | ||
*/ | ||
export function provideAxiosMiddleware(resolve: Resolve) { | ||
const logHandler = resolve(KnownToken.Axios.Middleware.Log.handler); | ||
|
||
return [HttpStatus.axiosMiddleware(), logMiddleware(logHandler)]; | ||
} |
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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { ConfigSource, createConfigSource } from '../../../config'; | ||
|
||
/** | ||
* Провайдер источника конфигурации. | ||
* @return Источник конфигурации. | ||
*/ | ||
export function provideConfigSource(): ConfigSource { | ||
// ВАЖНО: по умолчанию рассчитываем на process.env который предоставляется сборщиком (например webpack) | ||
if (typeof process !== 'undefined' && process.env) { | ||
return createConfigSource(process.env); | ||
} | ||
|
||
return createConfigSource({}); | ||
} |
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 |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { Resolve } from '../../../di'; | ||
import { KnownToken } from '../../../tokens'; | ||
import { FetchLogging } from '../../isomorphic/utils/fetch-logging'; | ||
import { log } from '../../../http'; | ||
|
||
/** | ||
* Провайдер промежуточных слоев для fetch. | ||
* @param resolve Функция для получения зависимости по токену. | ||
* @return Фабрика. | ||
*/ | ||
export function provideFetchMiddleware(resolve: Resolve) { | ||
const logger = resolve(KnownToken.logger); | ||
|
||
// ВАЖНО: если появятся еще промежуточные слои - не забыть разделить логирование на 2 части (ошибки и данные) | ||
return [log(new FetchLogging(logger))]; | ||
} |
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { Resolve } from '../../../di'; | ||
import { KnownToken } from '../../../tokens'; | ||
import { KnownHttpApiKey } from '../../isomorphic/types'; | ||
import { HttpApiHostPool } from '../../isomorphic/utils/http-api-host-pool'; | ||
|
||
/** | ||
* Провайдер известных http-хостов. | ||
* @param resolve Функция для получения зависимости по токену. | ||
* @return Пул известных http-хостов. | ||
*/ | ||
export function provideKnownHttpApiHosts(resolve: Resolve): HttpApiHostPool<KnownHttpApiKey> { | ||
const source = resolve(KnownToken.Config.source); | ||
|
||
return new HttpApiHostPool<KnownHttpApiKey>( | ||
{ | ||
ilium: 'PUBLIC_API_URL_ILIUM', | ||
simaV3: 'PUBLIC_API_URL_SIMALAND_V3', | ||
simaV4: 'PUBLIC_API_URL_SIMALAND_V4', | ||
simaV6: 'PUBLIC_API_URL_SIMALAND_V6', | ||
chponkiV2: 'PUBLIC_API_URL_CHPONKI_V2', | ||
}, | ||
source, | ||
); | ||
} |
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 |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { | ||
BrowserClient, | ||
Hub, | ||
defaultIntegrations, | ||
defaultStackParser, | ||
makeFetchTransport, | ||
} from '@sentry/browser'; | ||
import { Resolve } from '../../../di'; | ||
import { Logger, createLogger } from '../../../log'; | ||
import { KnownToken } from '../../../tokens'; | ||
import { createSentryHandler } from '../../../log/handler/sentry'; | ||
|
||
/** | ||
* Провайдер Logger'а. | ||
* @param resolve Функция для получения зависимости по токену. | ||
* @return Logger. | ||
*/ | ||
export function provideLogger(resolve: Resolve): Logger { | ||
const source = resolve(KnownToken.Config.source); | ||
const config = resolve(KnownToken.Config.base); | ||
|
||
const client = new BrowserClient({ | ||
transport: makeFetchTransport, | ||
stackParser: defaultStackParser, | ||
dsn: source.require('PUBLIC_SENTRY_DSN'), | ||
release: source.require('SENTRY_RELEASE'), | ||
environment: source.require('PUBLIC_SENTRY_ENVIRONMENT'), | ||
integrations: [...defaultIntegrations], | ||
}); | ||
|
||
const hub = new Hub(client); | ||
|
||
hub.setTag('url', window.location.href); | ||
|
||
const logger = createLogger(); | ||
|
||
logger.subscribe(createSentryHandler(hub)); | ||
|
||
if (config.env === 'development') { | ||
logger.subscribe(event => { | ||
switch (event.type) { | ||
case 'debug': | ||
// eslint-disable-next-line no-console | ||
console.debug(event.data); | ||
break; | ||
case 'error': | ||
// eslint-disable-next-line no-console | ||
console.error(event.data); | ||
break; | ||
} | ||
}); | ||
} | ||
|
||
return logger; | ||
} |
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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { Resolve } from '../../../di'; | ||
import { KnownToken } from '../../../tokens'; | ||
import { BridgeClientSide, SsrBridge } from '../../../utils/ssr'; | ||
|
||
/** | ||
* Провайдер клиентской части "моста" для передачи данных между сервером и клиентом. | ||
* @param resolve Функция для получения зависимости по токену. | ||
* @return Клиентская часть "моста". | ||
*/ | ||
export function provideSsrBridgeClientSide(resolve: Resolve): BridgeClientSide<unknown> { | ||
const config = resolve(KnownToken.Config.base); | ||
|
||
return SsrBridge.resolve(config.appName); | ||
} |