I have checked all these things :-
- Ip whitelist
- Async funtion try catch
- Account password
- Nodejs version
Now still I am getting the error
Mongo connection code
const connectDB = async() =>{
await mongoose.createConnection(URI, {
useNewUrlParser: true,
useUnifiedTopology: true,
useCreateIndex: true, })
.then(() => console.log("Database connected!"))
.catch(err => console.log(err));
}
Post request
connectDB();
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'jade');
app.use(cor());
app.use(logger('dev'));
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));
// app.use('/', indexRouter);
// app.use('/users', usersRouter);
app.post('/shorturl',async (req,res)=>{
let shortUrl = new shorturl({full:req.body.fullurl})
console.log("Saving!!")
await shortUrl.save()
.then(()=>{ console.log("Inserted!!"); res.send(shortUrl.short)}).catch(error => console.log("ERROR"));
//await shorturl.create({full:req.body.fullurl})
// if(shortUrl == null )return res.sendStatus(404);
})
GET
Its making a get req but not returning any thing.Not even any error its just making get req again and again.
app.get('/:shortUrl',async (req,res)=>{
try{
const shortUrl = await shorturl.findOne({ short: req.params.shortUrl })
.then(()=>{
if(shortUrl == null) return res.sendStatus(404);
res.redirect(shortUrl.full);
})
}
catch{(error)=> console.log(error)};
})