Skip to content

Commit 95c4a4b

Browse files
committed
fix cors error
1 parent 3130c14 commit 95c4a4b

File tree

4 files changed

+2285
-2
lines changed

4 files changed

+2285
-2
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
# Todo-Node-App
22
A basic todo application built in node js and mongo db
3+
base: https://insect-mindshare.cyclic-app.com/

app.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@ require('dotenv').config();
33
const express = require('express');
44
const app = express();
55
const mongoose = require('mongoose');
6+
const cors = require('cors');
67
const todoController = require('./controllers/todoController');
78
const PORT = process.env.PORT || 3000;
89

910
//routes api
11+
app.use(cors());
1012
app.use(express.json());
1113
app.get('/', function(req, res){
1214
res.status(200).json({message: 'Welcome to isaac todo api'});
@@ -20,7 +22,10 @@ app.get('/todos/:todoId', todoController.getTodoById);
2022
//listener
2123
app.listen(PORT, function(){
2224
console.log('Server has started to run');
23-
mongoose.connect(process.env.DB_URL)
25+
mongoose.connect(process.env.DB_URL,{
26+
useNewUrlParser: true,
27+
useUnifiedTopology: true,
28+
})
2429
.then(function(){
2530
console.log('DB is connected');
2631
})

0 commit comments

Comments
 (0)