Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added CORS module to avoid CORS errors #26

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 10 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
@@ -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;
14 changes: 14 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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'"
},
Expand All @@ -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",
Expand All @@ -25,6 +26,7 @@
},
"homepage": "https://github.com/annthurium/affirmations#readme",
"dependencies": {
"cors": "^2.8.5",
"express": "^4.17.1"
},
"devDependencies": {
Expand Down