Browse Source

prepare the server

Sven Czarnian 2 năm trước cách đây
mục cha
commit
31c9739d38
3 tập tin đã thay đổi với 22 bổ sung0 xóa
  1. 14 0
      package-lock.json
  2. 1 0
      package.json
  3. 7 0
      src/main.ts

+ 14 - 0
package-lock.json

@@ -14,6 +14,7 @@
         "@nestjs/core": "^9.0.0",
         "@nestjs/mongoose": "^9.2.0",
         "@nestjs/platform-express": "^9.0.0",
+        "helmet": "^6.0.0",
         "js-yaml": "^4.1.0",
         "mongoose": "^6.6.7",
         "reflect-metadata": "^0.1.13",
@@ -4550,6 +4551,14 @@
         "url": "https://github.com/sponsors/ljharb"
       }
     },
+    "node_modules/helmet": {
+      "version": "6.0.0",
+      "resolved": "https://registry.npmjs.org/helmet/-/helmet-6.0.0.tgz",
+      "integrity": "sha512-FO9RpR1wNJepH/GbLPQVtkE2eESglXL641p7SdyoT4LngHFJcZheHMoyUcjCZF4qpuMMO1u5q6RK0l9Ux8JBcg==",
+      "engines": {
+        "node": ">=14.0.0"
+      }
+    },
     "node_modules/hexoid": {
       "version": "1.0.0",
       "resolved": "https://registry.npmjs.org/hexoid/-/hexoid-1.0.0.tgz",
@@ -12004,6 +12013,11 @@
       "resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.0.3.tgz",
       "integrity": "sha512-l3LCuF6MgDNwTDKkdYGEihYjt5pRPbEg46rtlmnSPlUbgmB8LOIrKJbYYFBSbnPaJexMKtiPO8hmeRjRz2Td+A=="
     },
+    "helmet": {
+      "version": "6.0.0",
+      "resolved": "https://registry.npmjs.org/helmet/-/helmet-6.0.0.tgz",
+      "integrity": "sha512-FO9RpR1wNJepH/GbLPQVtkE2eESglXL641p7SdyoT4LngHFJcZheHMoyUcjCZF4qpuMMO1u5q6RK0l9Ux8JBcg=="
+    },
     "hexoid": {
       "version": "1.0.0",
       "resolved": "https://registry.npmjs.org/hexoid/-/hexoid-1.0.0.tgz",

+ 1 - 0
package.json

@@ -26,6 +26,7 @@
     "@nestjs/core": "^9.0.0",
     "@nestjs/mongoose": "^9.2.0",
     "@nestjs/platform-express": "^9.0.0",
+    "helmet": "^6.0.0",
     "js-yaml": "^4.1.0",
     "mongoose": "^6.6.7",
     "reflect-metadata": "^0.1.13",

+ 7 - 0
src/main.ts

@@ -1,8 +1,15 @@
 import { NestFactory } from '@nestjs/core';
+import { ValidationPipe } from '@nestjs/common';
+import helmet from 'helmet';
 import { AppModule } from './app.module';
 
 async function bootstrap() {
   const app = await NestFactory.create(AppModule);
+
+  app.use(helmet());
+  app.enableCors();
+  app.useGlobalPipes(new ValidationPipe({ whitelist: true }));
+
   await app.listen(3000);
 }
 bootstrap();