Skip to content
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
5 changes: 3 additions & 2 deletions api/routes/facts.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
const express = require('express');

const router = express.Router();
const mongoose = require('mongoose')
const Fact = require('./models/fact')
Expand All @@ -26,7 +25,7 @@ router.get('/', (req, res, next) => {
res.status(500).json(err)
})
})

next();
// GET ALL THE FACTS

// Fact.find()
Expand Down Expand Up @@ -66,6 +65,7 @@ router.post('/', (req, res, next) => {
error: err
})
})
next();
})


Expand All @@ -83,6 +83,7 @@ router.delete('/:factsId', (req, res, next) => {
error: err
})
})
next();
})

module.exports = router
2 changes: 1 addition & 1 deletion api/routes/models/fact.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ const factSchema = mongoose.Schema({
author: String
})

module.exports = mongoose.model('Fact', factSchema)
module.exports = mongoose.model('Fact', factSchema);
8 changes: 3 additions & 5 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const app = express();
const morgan = require('morgan')
const bodyParser = require('body-parser')
const mongoose = require('mongoose')

const cors = require('cors')
const factRoutes = require('./api/routes/facts')


Expand All @@ -18,15 +18,13 @@ app.use(morgan('dev'))

app.use(bodyParser.urlencoded({ extended: false }))
app.use(bodyParser.json())

app.use(cors())


//CORS error removal
app.use((req, res, next) => {
res.header('Access-Control-Allow-Origin', '*')
res.header('Access-Control-Allow-Headers', '*')
if (req.method === 'OPTIONS') {
res.header('Access-Control-Allow-Methods', 'PUT,POST,PATCH,DELETE,GET')
res.header('Access-Control-Allow-Methods', '*')
return res.status(200).json({})
}
next();
Expand Down
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.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@
"homepage": "https://github.com/MLSA-SRM/GET-some-REST#readme",
"dependencies": {
"body-parser": "^1.19.0",
"cors": "^2.8.5",
"express": "^4.17.1",
"mongoose": "^5.10.3",
"morgan": "^1.10.0"
},
"devDependencies": {
"nodemon": "^2.0.4"
}
}
}