From 767213b7be44cb94551fc43e63619bda2727883c Mon Sep 17 00:00:00 2001 From: Oleg Shuralev Date: Sun, 5 Jan 2020 14:19:54 +0300 Subject: [PATCH] [API] Add CORS --- api/app.js | 13 ++++++++++--- api/package-lock.json | 14 ++++++++++++++ api/package.json | 5 +++-- 3 files changed, 27 insertions(+), 5 deletions(-) diff --git a/api/app.js b/api/app.js index ac4bd9728a..5b0c5dfb66 100644 --- a/api/app.js +++ b/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 diff --git a/api/package-lock.json b/api/package-lock.json index 1c92d81257..fff96ed5c9 100644 --- a/api/package-lock.json +++ b/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", diff --git a/api/package.json b/api/package.json index 27231fe9ee..ab49a02fb2 100644 --- a/api/package.json +++ b/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"