From de8f33cd007d9b16fe98beb8bdb136fcacff352b Mon Sep 17 00:00:00 2001 From: ryzetech Date: Thu, 19 Jan 2023 23:28:37 +0100 Subject: [PATCH] add cors middleware --- app.js | 7 +++++-- package.json | 3 ++- yarn.lock | 15 ++++++++++++++- 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/app.js b/app.js index 365df5f..897bf34 100644 --- a/app.js +++ b/app.js @@ -12,6 +12,7 @@ const NodeCache = require("node-cache"); const jp = require('jsonpath'); const { PrismaClient } = require('@prisma/client'); const prisma = new PrismaClient(); +const cors = require('cors'); // set up things const cache = new NodeCache({ stdTTL: config.checkperiod * 3 }); @@ -35,8 +36,9 @@ let root = { let data = await prisma.space.findUnique({ where: { id: id } }); return data.open; }, - spaces: () => { - return prisma.space.findMany(); + spaces: async () => { + let data = await prisma.space.findMany(); + return data; } }; @@ -46,6 +48,7 @@ app.use('/graphql', graphqlHTTP({ rootValue: root, graphiql: true, })); +app.use(cors()); app.listen(config.port || 4000); diff --git a/package.json b/package.json index 8e362f0..0adc46c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,7 @@ { "dependencies": { "@prisma/client": "^4.9.0", + "cors": "^2.8.5", "express": "^4.18.2", "express-graphql": "^0.12.0", "graphql": "^16.6.0", @@ -12,6 +13,6 @@ "scripts": { "start": "node app.js", "generate": "npx prisma generate dev", - "migrate": "npx prisma migrate" + "migrate": "npx prisma migrate dev" } } diff --git a/yarn.lock b/yarn.lock index 5c63361..5941edf 100644 --- a/yarn.lock +++ b/yarn.lock @@ -90,6 +90,14 @@ cookie@0.5.0: resolved "https://registry.yarnpkg.com/cookie/-/cookie-0.5.0.tgz#d1f5d71adec6558c58f389987c366aa47e994f8b" integrity sha512-YZ3GUyn/o8gfKJlnlX7g7xq4gyO6OSuhGPKaaGssGB2qgDUS0gPgtTvoyZLTt9Ab6dC4hfc9dV5arkvc/OCmrw== +cors@^2.8.5: + version "2.8.5" + resolved "https://registry.yarnpkg.com/cors/-/cors-2.8.5.tgz#eac11da51592dd86b9f06f6e7ac293b3df875d29" + integrity sha512-KIHbLJqu73RGr/hnbrO9uBeixNGuvSQjul/jdFvS/KFSIH1hWVd1ng7zOHx+YrEfInLG7q4n6GHQ9cDtxv/P6g== + dependencies: + object-assign "^4" + vary "^1" + debug@2.6.9: version "2.6.9" resolved "https://registry.yarnpkg.com/debug/-/debug-2.6.9.tgz#5d128515df134ff327e90a4c93f4e077a536341f" @@ -392,6 +400,11 @@ node-fetch@2: dependencies: whatwg-url "^5.0.0" +object-assign@^4: + version "4.1.1" + resolved "https://registry.yarnpkg.com/object-assign/-/object-assign-4.1.1.tgz#2109adc7965887cfc05cbbd442cac8bfbb360863" + integrity sha512-rJgTQnkUnH1sFw8yT6VSU3zD3sWmu6sZhIseY8VX+GRu3P6F7Fu+JNDoXfklElbLJSnc3FUQHVe4cU5hj+BcUg== + object-inspect@^1.9.0: version "1.12.3" resolved "https://registry.yarnpkg.com/object-inspect/-/object-inspect-1.12.3.tgz#ba62dffd67ee256c8c086dfae69e016cd1f198b9" @@ -588,7 +601,7 @@ utils-merge@1.0.1: resolved "https://registry.yarnpkg.com/utils-merge/-/utils-merge-1.0.1.tgz#9f95710f50a267947b2ccc124741c1028427e713" integrity sha512-pMZTvIkT1d+TFGvDOqodOclx0QWkkgi6Tdoa8gC8ffGAAqz9pzPTZWAybbsHHoED/ztMtkv/VoYTYyShUn81hA== -vary@~1.1.2: +vary@^1, vary@~1.1.2: version "1.1.2" resolved "https://registry.yarnpkg.com/vary/-/vary-1.1.2.tgz#2299f02c6ded30d4a5961b0b9f74524a18f634fc" integrity sha512-BNGbWLfd0eUPabhkXUVm0j8uuvREyTh5ovRa/dyow/BqAbZJyC+5fU+IzQOzmAKzYqYRAISoRhdQr3eIZ/PXqg==