Oleg Shuralev 5 lat temu
rodzic
commit
767213b7be
3 zmienionych plików z 27 dodań i 5 usunięć
  1. 10 3
      api/app.js
  2. 14 0
      api/package-lock.json
  3. 3 2
      api/package.json

+ 10 - 3
api/app.js

@@ -1,10 +1,17 @@
 'use strict'
 
-const path = require('path')
-const AutoLoad = require('fastify-autoload')
+const path = require('path');
+const AutoLoad = require('fastify-autoload');
+const CORS = require('fastify-cors');
 
 module.exports = function (fastify, opts, next) {
-  // Place here your custom code!
+  fastify.register(CORS, {
+    origin: 'http://localhost:3000',
+    preflight: true,
+    preflightContinue: true,
+    credentials: true,
+    methods: ['GET', 'PUT', 'PATCH', 'POST', 'DELETE'],
+  })
 
   // Do not touch the following lines
 

+ 14 - 0
api/package-lock.json

@@ -1304,6 +1304,15 @@
         "yargs-parser": "^13.0.0"
       }
     },
+    "fastify-cors": {
+      "version": "3.0.0",
+      "resolved": "https://registry.npmjs.org/fastify-cors/-/fastify-cors-3.0.0.tgz",
+      "integrity": "sha512-bLV7OIZ7ojvLaf0jOEsqAO4ShrBSc6412R6SVDIrFK6vIUAezTAVgk9MqcklZnc3ch/N/IC9kGPu5AfhqAIHkg==",
+      "requires": {
+        "fastify-plugin": "^1.6.0",
+        "vary": "^1.1.2"
+      }
+    },
     "fastify-plugin": {
       "version": "1.6.0",
       "resolved": "https://registry.npmjs.org/fastify-plugin/-/fastify-plugin-1.6.0.tgz",
@@ -4749,6 +4758,11 @@
         "spdx-expression-parse": "^3.0.0"
       }
     },
+    "vary": {
+      "version": "1.1.2",
+      "resolved": "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz",
+      "integrity": "sha1-IpnwLG3tMNSllhsLn3RSShj2NPw="
+    },
     "verror": {
       "version": "1.10.0",
       "resolved": "https://registry.npmjs.org/verror/-/verror-1.10.0.tgz",

+ 3 - 2
api/package.json

@@ -16,9 +16,10 @@
   "license": "ISC",
   "dependencies": {
     "fastify": "^2.0.0",
-    "fastify-plugin": "^1.5.0",
     "fastify-autoload": "^1.0.0",
-    "fastify-cli": "^1.3.0"
+    "fastify-cli": "^1.3.0",
+    "fastify-cors": "^3.0.0",
+    "fastify-plugin": "^1.5.0"
   },
   "devDependencies": {
     "tap": "^12.5.3"