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 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..9eee158 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'" }, @@ -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", @@ -25,6 +26,7 @@ }, "homepage": "https://github.com/annthurium/affirmations#readme", "dependencies": { + "cors": "^2.8.5", "express": "^4.17.1" }, "devDependencies": {