From a534b34ae8f2b7814bdc409930d7b5d3252193ef Mon Sep 17 00:00:00 2001 From: Adithya Kamath Date: Fri, 4 Sep 2020 02:43:57 +0530 Subject: [PATCH 1/3] Added CORS module to avoid CORS errors --- index.js | 16 ++++++++++------ package-lock.json | 14 ++++++++++++++ package.json | 3 ++- 3 files changed, 26 insertions(+), 7 deletions(-) diff --git a/index.js b/index.js index fdf7600..071d6a1 100644 --- a/index.js +++ b/index.js @@ -1,14 +1,18 @@ -const express = require('express'); -const getRandomAffirmation = require('./random_affirmation'); +const express = require("express"); +const cors = require("cors"); + +const getRandomAffirmation = require("./random_affirmation"); const app = express(); let PORT = process.env.PORT || 3000; - -app.get('/', (req, res) => { - res.json({affirmation: getRandomAffirmation()}); +app.use(cors()); +app.get("/", (req, res) => { + res.json({ affirmation: getRandomAffirmation() }); }); -const server = app.listen(PORT, () => console.log(`Server is live at localhost:${PORT}`)); +const server = app.listen(PORT, () => + console.log(`Server is live at localhost:${PORT}`) +); module.exports = server; diff --git a/package-lock.json b/package-lock.json index 23e0cc3..124ff2e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1312,6 +1312,15 @@ "integrity": "sha1-tf1UIgqivFq1eqtxQMlAdUUDwac=", "dev": true }, + "cors": { + "version": "2.8.5", + "resolved": "https://registry.npmjs.org/cors/-/cors-2.8.5.tgz", + "integrity": "sha512-KIHbLJqu73RGr/hnbrO9uBeixNGuvSQjul/jdFvS/KFSIH1hWVd1ng7zOHx+YrEfInLG7q4n6GHQ9cDtxv/P6g==", + "requires": { + "object-assign": "^4", + "vary": "^1" + } + }, "cross-spawn": { "version": "6.0.5", "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-6.0.5.tgz", @@ -3665,6 +3674,11 @@ "integrity": "sha512-fexhUFFPTGV8ybAtSIGbV6gOkSv8UtRbDBnAyLQw4QPKkgNlsH2ByPGtMUqdWkos6YCRmAqViwgZrJc/mRDzZQ==", "dev": true }, + "object-assign": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz", + "integrity": "sha1-IQmtx5ZYh8/AXLvUQsrIv7s2CGM=" + }, "object-copy": { "version": "0.1.0", "resolved": "https://registry.npmjs.org/object-copy/-/object-copy-0.1.0.tgz", diff --git a/package.json b/package.json index c794247..b925325 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "description": "an api for getting affirmations", "main": "index.js", "scripts": { - "test": "jest --coverage --forceExit", + "test": "jest --coverage --forceExit", "start": "node index.js", "update-coc": "weallbehave -o . && git add CODE_OF_CONDUCT.md && git commit -m 'docs(coc): updated CODE_OF_CONDUCT.md'" }, @@ -25,6 +25,7 @@ }, "homepage": "https://github.com/annthurium/affirmations#readme", "dependencies": { + "cors": "^2.8.5", "express": "^4.17.1" }, "devDependencies": { From 2082f3ddaefb7905a28ab850b009643e80de359c Mon Sep 17 00:00:00 2001 From: Adithya Kamath Date: Thu, 17 Sep 2020 02:39:30 +0530 Subject: [PATCH 2/3] Added NPM version on package.json --- package.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index b925325..9eee158 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,8 @@ "url": "git+https://github.com/annthurium/affirmations.git" }, "engines": { - "node": "8.0.0" + "node": "8.0.0", + "npm": "5.0.0" }, "author": { "name": "tilde", From 73a178e569932c8d281fd221a3f1ed91d8d546a4 Mon Sep 17 00:00:00 2001 From: Adithya Kamath Date: Thu, 17 Sep 2020 02:44:43 +0530 Subject: [PATCH 3/3] Added NPM version on package.json --- .github/workflows/nodejs.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/nodejs.yml b/.github/workflows/nodejs.yml index 52d7757..9857478 100644 --- a/.github/workflows/nodejs.yml +++ b/.github/workflows/nodejs.yml @@ -14,6 +14,7 @@ jobs: - uses: actions/setup-node@v1 with: node-version: '8.x' + npm: '5.x' - name: Installing dependencies run: npm - name: Running tests