Skip to content

Commit

Permalink
Merge pull request #48 from sima-land/38-bun-deno-support
Browse files Browse the repository at this point in the history
Шаг 10 #38
  • Loading branch information
krutoo committed Jun 5, 2023
2 parents d9fd499 + 6cf19ea commit 05dcfb6
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 7 deletions.
11 changes: 11 additions & 0 deletions package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
},
"dependencies": {
"@humanwhocodes/env": "^2.2.2",
"@krutoo/fetch-tools": "^0.0.4",
"@opentelemetry/api": "^1.4.1",
"@opentelemetry/exporter-prometheus": "^0.38.0",
"@opentelemetry/exporter-trace-otlp-http": "^0.39.1",
Expand Down
1 change: 1 addition & 0 deletions src/cache/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/**
* Простейший интерфейс кэша.
* @todo Рассмотреть web-стандарт CacheStorage.
*/
export interface Cache {
/**
Expand Down
1 change: 1 addition & 0 deletions src/http-server/middleware/log.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { toMilliseconds } from '../../utils/number';

/**
* Возвращает новый middleware для логирования запросов.
* @todo Переделать на получение абстрактного LogHandler'а, бизнес-логику перенести в пресеты.
* @param config Конфиг.
* @param logger Logger.
* @return Middleware.
Expand Down
4 changes: 2 additions & 2 deletions src/http-server/utils.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { Handler, Request, Response } from 'express';
import type { ConventionalJson, PageAssets, PageTemplate, PageTemplateData } from './types';
import type { BaseConfig } from '../config/types';
import { isIP } from 'net';
import net from 'node:net';

/**
* Объединяет промежуточные слои в один.
Expand Down Expand Up @@ -29,7 +29,7 @@ export function getXClientIp(req: Request): string {
const headerValue =
req.get('x-client-ip') || req.get('x-forwarded-for') || req.socket.remoteAddress || '';

return isIP(headerValue) ? headerValue : '';
return net.isIP(headerValue) ? headerValue : '';
}

/**
Expand Down
7 changes: 7 additions & 0 deletions src/http/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export type { Handler, Enhancer, Middleware } from '@krutoo/fetch-tools';

// @todo здесь будет все и для клиентов и для серверов
// - мидлвари (клиент/сервер): log, validateStatus, defaultHeaders, collectCookie, jwt?, ...
// - хендлеры (сервер): healthCheck, ...
// - sauce (клиент): ???
// http-server и http-client постепенно станут deprecated
2 changes: 1 addition & 1 deletion src/tokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export const KnownToken = {
Server: {
factory: createToken<() => Application>('server/factory'),
Handler: {
healthCheck: createToken<Handler>('middleware/health-check'),
healthCheck: createToken<Handler>('handler/health-check'),
},
Middleware: {
request: createToken<Handler>('middleware/request'),
Expand Down
8 changes: 4 additions & 4 deletions src/utils/webpack/env/utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { EnvPluginOptions } from './types';
import { readFileSync, existsSync } from 'fs';
import path from 'path';
import fs from 'node:fs';
import path from 'node:path';
import dotenv from 'dotenv';

/**
Expand All @@ -17,8 +17,8 @@ export function defineEnv(
try {
const dotenvPath = path.join(process.cwd(), `.env.${process.env.NODE_ENV}`);

if (existsSync(dotenvPath)) {
const parsed = dotenv.parse(readFileSync(dotenvPath, 'utf-8'));
if (fs.existsSync(dotenvPath)) {
const parsed = dotenv.parse(fs.readFileSync(dotenvPath, 'utf-8'));

// @todo дёрнуть бы эту логику из пакета dotenv, https://github.com/motdotla/dotenv/issues/690
for (const key of Object.keys(parsed)) {
Expand Down

0 comments on commit 05dcfb6

Please sign in to comment.