From 2f53e947e0554102c8742f2c281a4d4bfd5d4817 Mon Sep 17 00:00:00 2001 From: Naidu Date: Wed, 16 Oct 2024 23:27:10 -0700 Subject: [PATCH] added fastify cros --- node_modules/.package-lock.json | 1 + package-lock.json | 1 + src/index.js | 7 ++++++- 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/node_modules/.package-lock.json b/node_modules/.package-lock.json index 99eb3e58..b11c890d 100644 --- a/node_modules/.package-lock.json +++ b/node_modules/.package-lock.json @@ -5828,6 +5828,7 @@ "version": "5.2.0", "resolved": "https://registry.npmjs.org/fastify-cors/-/fastify-cors-5.2.0.tgz", "integrity": "sha512-Lde71qT23M3Ip3pmny3uN6q6lQ4J5J0/YWoqe2stL4sMT99R5LEtTJ2La2zijFOR5OFhxvxqGgR7BIc2x3amPg==", + "license": "MIT", "dependencies": { "fastify-plugin": "^3.0.0", "vary": "^1.1.2" diff --git a/package-lock.json b/package-lock.json index e841c8e3..3f928ea4 100644 --- a/package-lock.json +++ b/package-lock.json @@ -5893,6 +5893,7 @@ "version": "5.2.0", "resolved": "https://registry.npmjs.org/fastify-cors/-/fastify-cors-5.2.0.tgz", "integrity": "sha512-Lde71qT23M3Ip3pmny3uN6q6lQ4J5J0/YWoqe2stL4sMT99R5LEtTJ2La2zijFOR5OFhxvxqGgR7BIc2x3amPg==", + "license": "MIT", "dependencies": { "fastify-plugin": "^3.0.0", "vary": "^1.1.2" diff --git a/src/index.js b/src/index.js index 2ad09141..38ab3ab9 100644 --- a/src/index.js +++ b/src/index.js @@ -8,9 +8,10 @@ const storeController = require("./controllers/storeController.js") const boom = require("boom"); const bcrypt = require('bcrypt'); const { ProfilePictureStore,generateinstallationId,Store} = require("./models/store"); +const cors = require('fastify-cors'); -const cors = require("cors"); +//const cors = require("cors"); const swagger = require("./config/swagger"); const rawBody = require('raw-body') const uuidv4 = require("uuid").v4; @@ -25,6 +26,10 @@ const fastify = require("fastify")({ // const Fastify = require("fastify"); +fastify.register(cors, { + origin: 'http://localhost:3001', // Allow only your frontend URL + methods: ['GET', 'POST', 'PUT', 'DELETE'], // Allowed HTTP methods +}); // const Fastify = require("fastify");