Skip to content

Commit fb61795

Browse files
committed
fix structure main
1 parent a06eaa4 commit fb61795

File tree

9 files changed

+88
-131
lines changed

9 files changed

+88
-131
lines changed

package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@
6363
"bullmq": "^4.14.0",
6464
"class-transformer": "^0.5.1",
6565
"class-validator": "^0.14.0",
66+
"cookie-parser": "^1.4.6",
67+
"helmet": "^7.1.0",
6668
"ioredis": "^5.3.2",
6769
"loglevel": "^1.8.1",
6870
"mongoose": "^8.0.2",
@@ -91,6 +93,7 @@
9193
"@nestjs/testing": "^10.1.3",
9294
"@swc/cli": "^0.1.63",
9395
"@swc/core": "^1.3.99",
96+
"@types/cookie-parser": "^1.4.6",
9497
"@types/express": "^4.17.17",
9598
"@types/jest": "^29.5.2",
9699
"@types/node": "^18.0.0",
@@ -112,6 +115,7 @@
112115
"prettier": "^3.0.0",
113116
"source-map-support": "^0.5.21",
114117
"supertest": "^6.3.3",
118+
"swagger-themes": "^1.4.2",
115119
"ts-jest": "^29.1.0",
116120
"ts-loader": "^9.4.3",
117121
"ts-node": "^10.9.1",

src/config.ts

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { MongooseModuleOptions } from '@nestjs/mongoose';
22
import { RedisOptions } from 'ioredis';
3+
import { HelmetOptions } from 'helmet';
34
import { SwaggerCustomOptions } from '@nestjs/swagger';
45
import { IAuthModuleOptions } from '@nestjs/passport';
56
import { JwtModuleOptions } from '@nestjs/jwt';
@@ -10,6 +11,12 @@ export interface MongoosePlugin {
1011
options?: Record<string, any>; // eslint-disable-line @typescript-eslint/no-explicit-any
1112
}
1213
export interface ConfigInstance {
14+
application: {
15+
bodyParser: {
16+
limit: string
17+
}
18+
}
19+
helmet: HelmetOptions
1320
mongoose: {
1421
uri: string;
1522
options: MongooseModuleOptions;
@@ -36,12 +43,24 @@ export interface ConfigInstance {
3643
}
3744

3845
export default (): ConfigInstance => ({
39-
// redis: {
40-
// host: process.env.REDIS_HOST || 'localhost',
41-
// port: parseInt(process.env.REDIS_PORT) || 6379,
42-
// user: process.env.REDIS_USER || '',
43-
// password: process.env.REDIS_PASSWORD || '',
44-
// },
46+
application: {
47+
bodyParser: {
48+
limit: '500mb',
49+
},
50+
},
51+
helmet: {
52+
contentSecurityPolicy: {
53+
directives: {
54+
defaultSrc: ["'self'"],
55+
objectSrc: ["'self'"],
56+
frameSrc: ["'self'"],
57+
styleSrc: ["'self'"],
58+
fontSrc: ["'self'"],
59+
imgSrc: ["'self'"],
60+
scriptSrc: ["'self'"],
61+
},
62+
},
63+
},
4564
ioredis: {
4665
uri: process.env['REDIS_URI'] || 'redis://localhost:6379/0',
4766
options: {
@@ -54,16 +73,7 @@ export default (): ConfigInstance => ({
5473
options: {
5574
directConnection: true,
5675
},
57-
plugins: [
58-
// {
59-
// package: 'mongoose-delete',
60-
// enabled: true,
61-
// options: {
62-
// overrideMethods: true,
63-
// deletedAt: true,
64-
// },
65-
// },
66-
],
76+
plugins: [],
6777
},
6878
passport: {
6979
options: {

src/core/backends/backends.controller.spec.ts.old

Lines changed: 0 additions & 47 deletions
This file was deleted.

src/core/backends/backends.service.spec.ts.old

Lines changed: 0 additions & 47 deletions
This file was deleted.

src/core/keyrings/_dto/keyrings.dto.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,18 @@
11
import { ApiProperty } from '@nestjs/swagger';
2-
import { IsMongoId, IsNotEmpty, IsString } from 'class-validator';
2+
import { IsDateString, IsIP, IsMongoId, IsNotEmpty, IsString } from 'class-validator';
33
import { CustomFieldsDto } from '~/_common/abstracts/dto/custom-fields.dto';
4-
import { Prop } from '@nestjs/mongoose';
54

65
export class KeyringsCreateDto extends CustomFieldsDto {
76
@IsString()
87
@IsNotEmpty()
98
@ApiProperty()
10-
public secretKey: string;
9+
public token: string;
1110

12-
@Prop({
13-
type: [String],
14-
})
11+
@IsString({ each: true })
12+
@IsIP(4, { each: true })
1513
public allowedNetworks?: string[];
1614

17-
@Prop({ type: Date })
15+
@IsDateString()
1816
public suspendedAt?: Date;
1917
}
2018

src/core/keyrings/_schemas/keyrings.schema.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@ export type KeyringsDocument = Keyrings & Document;
77
@Schema({ versionKey: false })
88
export class Keyrings extends AbstractSchema {
99
@Prop({
10-
type: Boolean,
10+
type: String,
11+
unique: true,
1112
})
12-
public secretKey: string;
13+
public token: string;
1314

1415
@Prop({
1516
type: [String],

src/main.ts

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,20 @@ import configInstance from './config';
44
import { Logger } from '@nestjs/common';
55
import { NestExpressApplication } from '@nestjs/platform-express';
66
import { utilities as nestWinstonModuleUtilities, WinstonModule } from 'nest-winston';
7+
import cookieParser from 'cookie-parser';
78
import { createLogger } from 'winston';
89
import * as winston from 'winston';
910
import 'winston-mongodb';
1011
import { AllExceptionFilter } from './_common/filters/all-exception.filter';
1112
import { IdentitiesValidationFilter } from './_common/filters/identities-validation.filter';
1213
import { MongooseValidationFilter } from './_common/filters/mongoose-validation.filter';
14+
import { Response } from 'express';
15+
import passport from 'passport';
16+
import { rawBodyBuffer } from '~/_common/middlewares/raw-body-buffer.middleware';
1317

1418
declare const module: any;
1519
(async (): Promise<void> => {
20+
const cfg = configInstance();
1621
const winstonFormat = {
1722
pretty: winston.format.combine(
1823
winston.format.colorize(),
@@ -36,7 +41,7 @@ declare const module: any;
3641
format: winstonFormat.pretty,
3742
}),
3843
mongodb: new winston.transports.MongoDB({
39-
db: configInstance().mongoose.uri,
44+
db: cfg.mongoose.uri,
4045
collection: 'logs',
4146
level: 'debug',
4247
options: {
@@ -55,16 +60,18 @@ declare const module: any;
5560
logger: WinstonModule.createLogger({
5661
instance: winstonInstance,
5762
}),
58-
// rawBody: true,
63+
bodyParser: false,
64+
rawBody: true,
5965
cors: true,
6066
});
6167
// eslint-disable-next-line
62-
// app.use((_: any, res: Response, next: () => void) => {
63-
// res.removeHeader('x-powered-by')
64-
// next()
65-
// })
66-
// app.use(passport.initialize())
67-
// app.use(rawBodyBuffer(cfg?.application?.bodyParser));
68+
app.use((_: any, res: Response, next: () => void) => {
69+
res.removeHeader('x-powered-by')
70+
next()
71+
})
72+
app.use(passport.initialize())
73+
app.use(rawBodyBuffer(cfg?.application?.bodyParser));
74+
app.use(cookieParser())
6875
if (process.env.production !== 'production') {
6976
// eslint-disable-next-line @typescript-eslint/no-var-requires
7077
(await import('./swagger')).default(app);

src/swagger.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import { DocumentBuilder, SwaggerCustomOptions, SwaggerModule } from '@nestjs/swagger';
22
import { ConfigService } from '@nestjs/config';
33
import { NestExpressApplication } from '@nestjs/platform-express';
4-
import { Request, Response } from 'express';
4+
import { Response } from 'express';
5+
import { SwaggerTheme, SwaggerThemeName } from 'swagger-themes';
56
import { readFileSync } from 'fs';
67

78
export default function swagger(app: NestExpressApplication) {
@@ -14,13 +15,13 @@ export default function swagger(app: NestExpressApplication) {
1415
.addBearerAuth({ type: 'http', scheme: 'bearer', bearerFormat: 'JWT' }, 'access-token')
1516
.build();
1617
const document = SwaggerModule.createDocument(app, build);
18+
const theme = new SwaggerTheme('v3')
1719
SwaggerModule.setup(config.get<string>('swagger.path'), app, document, {
1820
...config.get<SwaggerCustomOptions>('swagger.options'),
1921
explorer: true,
2022
swaggerOptions: {},
23+
customCss: theme.getBuffer(<SwaggerThemeName>'dark'),
2124
});
2225

23-
app.getHttpAdapter().get(config.get<string>('swagger.api'), (req: Request, res: Response) => {
24-
res.json(document);
25-
});
26+
app.getHttpAdapter().get(config.get<string>('swagger.api'), (_, res: Response) => res.json(document));
2627
}

yarn.lock

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2360,6 +2360,13 @@
23602360
dependencies:
23612361
"@types/node" "*"
23622362

2363+
"@types/cookie-parser@^1.4.6":
2364+
version "1.4.6"
2365+
resolved "https://registry.yarnpkg.com/@types/cookie-parser/-/cookie-parser-1.4.6.tgz#002643c514cccf883a65cbe044dbdc38c0b92ade"
2366+
integrity sha512-KoooCrD56qlLskXPLGUiJxOMnv5l/8m7cQD2OxJ73NPMhuSz9PmvwRD6EpjDyKBVrdJDdQ4bQK7JFNHnNmax0w==
2367+
dependencies:
2368+
"@types/express" "*"
2369+
23632370
"@types/cookiejar@*":
23642371
version "2.1.5"
23652372
resolved "https://registry.yarnpkg.com/@types/cookiejar/-/cookiejar-2.1.5.tgz#14a3e83fa641beb169a2dd8422d91c3c345a9a78"
@@ -4092,11 +4099,24 @@ convert-source-map@^2.0.0:
40924099
resolved "https://registry.yarnpkg.com/convert-source-map/-/convert-source-map-2.0.0.tgz#4b560f649fc4e918dd0ab75cf4961e8bc882d82a"
40934100
integrity sha512-Kvp459HrV2FEJ1CAsi1Ku+MY3kasH19TFykTz2xWmMeq6bk2NU3XXvfJ+Q61m0xktWwt+1HSYf3JZsTms3aRJg==
40944101

4102+
cookie-parser@^1.4.6:
4103+
version "1.4.6"
4104+
resolved "https://registry.yarnpkg.com/cookie-parser/-/cookie-parser-1.4.6.tgz#3ac3a7d35a7a03bbc7e365073a26074824214594"
4105+
integrity sha512-z3IzaNjdwUC2olLIB5/ITd0/setiaFMLYiZJle7xg5Fe9KWAceil7xszYfHHBtDFYLSgJduS2Ty0P1uJdPDJeA==
4106+
dependencies:
4107+
cookie "0.4.1"
4108+
cookie-signature "1.0.6"
4109+
40954110
cookie-signature@1.0.6:
40964111
version "1.0.6"
40974112
resolved "https://registry.yarnpkg.com/cookie-signature/-/cookie-signature-1.0.6.tgz#e303a882b342cc3ee8ca513a79999734dab3ae2c"
40984113
integrity sha512-QADzlaHc8icV8I7vbaJXJwod9HWYp8uCqf1xa4OfNu1T7JVxQIrUgOWtHdNDtPiywmFbiS12VjotIXLrKM3orQ==
40994114

4115+
cookie@0.4.1:
4116+
version "0.4.1"
4117+
resolved "https://registry.yarnpkg.com/cookie/-/cookie-0.4.1.tgz#afd713fe26ebd21ba95ceb61f9a8116e50a537d1"
4118+
integrity sha512-ZwrFkGJxUR3EIoXtO+yVE69Eb7KlixbaeAWfBQB9vVsNn/o+Yw69gBWSSDK825hQNdN+wF8zELf3dFNl/kxkUA==
4119+
41004120
cookie@0.5.0:
41014121
version "0.5.0"
41024122
resolved "https://registry.yarnpkg.com/cookie/-/cookie-0.5.0.tgz#d1f5d71adec6558c58f389987c366aa47e994f8b"
@@ -5683,6 +5703,11 @@ hasown@^2.0.0:
56835703
dependencies:
56845704
function-bind "^1.1.2"
56855705

5706+
helmet@^7.1.0:
5707+
version "7.1.0"
5708+
resolved "https://registry.yarnpkg.com/helmet/-/helmet-7.1.0.tgz#287279e00f8a3763d5dccbaf1e5ee39b8c3784ca"
5709+
integrity sha512-g+HZqgfbpXdCkme/Cd/mZkV0aV3BZZZSugecH03kl38m/Kmdx8jKjBikpDj2cr+Iynv4KpYEviojNdTJActJAg==
5710+
56865711
hexoid@^1.0.0:
56875712
version "1.0.0"
56885713
resolved "https://registry.yarnpkg.com/hexoid/-/hexoid-1.0.0.tgz#ad10c6573fb907de23d9ec63a711267d9dc9bc18"
@@ -9372,6 +9397,11 @@ svg-pan-zoom@^3.6.1:
93729397
resolved "https://registry.yarnpkg.com/svg-pan-zoom/-/svg-pan-zoom-3.6.1.tgz#f880a1bb32d18e9c625d7715350bebc269b450cf"
93739398
integrity sha512-JaKkGHHfGvRrcMPdJWkssLBeWqM+Isg/a09H7kgNNajT1cX5AztDTNs+C8UzpCxjCTRrG34WbquwaovZbmSk9g==
93749399

9400+
swagger-themes@^1.4.2:
9401+
version "1.4.2"
9402+
resolved "https://registry.yarnpkg.com/swagger-themes/-/swagger-themes-1.4.2.tgz#c44ef2345a9f64d99fd0e6abb45d8aac8e603330"
9403+
integrity sha512-O+T8It8cy1X6lvrqC2QA6taslLoPnQ2oRmvW1Aub6TebKmWLdONqTo/CKDvo0t9W65QKC87/jnuEHjNx91oPzQ==
9404+
93759405
swagger-ui-dist@5.9.1:
93769406
version "5.9.1"
93779407
resolved "https://registry.yarnpkg.com/swagger-ui-dist/-/swagger-ui-dist-5.9.1.tgz#d0bcd614e3752da02df141846348f84468ae815e"

0 commit comments

Comments
 (0)