0

How to correct a 404 error when I fetch Data from DataBase?

I want to fetch data from SQL server using Redis-Caching , but when I send the request (GET http://localhost:4000/product/Data) => I see this error: GET /product/Data 404 7.390 ms - 33 GET /product/Data - - ms - - , How can I solve it ? server.js : const redis = require("redis"); const redisUrl='redis://127.0.0.1:6379'; // create Redis client on Redis port const client = redis.createClient(redisUrl); // create express application instance const Data=async(req,res,next)=>{ cache,getData } //Make request to DataBase for Data async function getData(req,res,next){ try{ console.log('Fetching Data From SQL server...') const Pull_Products=await SingletonSqlHandler.instance.sendQuery('SELECT * from dbo.getAllProducts()') // return Pull_Products; return res.status(200).send.json(Pull_Products) } catch(error){ console.error(error); res.status(500).json({error:error}) } } // Cache midleware async function cache(req,res,next){ console.log('Fetching Data From Cache...') const Pull_Products=await SingletonSqlHandler.instance.sendQuery('SELECT * from dbo.getAllProducts()') client.get(Pull_Products,(error,cachedData)=>{ if(error) throw error if(cachedData!=null){ res.send(setResponse(Pull_Products,cachedData)); } else { next(); } }) } module.exports={ Data:Data } productRoute.js: const router = require('express').Router(); const Redis=require('../redis-cache/server') router.get('/Data', Redis.Data); module.exports = router;

15th May 2020, 8:23 AM
Hiba Yousef
Hiba Yousef - avatar
1 Odpowiedź
0
Did you install redis server?
16th May 2020, 5:10 AM
Calviղ
Calviղ - avatar