我的nodejs api可以完美地与查询参数一起使用,但是同样的东西在Web浏览器中无法正常工作

时间:2019-10-09 13:13:55

标签: node.js rest api express

exports.findOne = (req, res) => {
    Geodata.find({'osmname':req.query.osmname}).select({'osm_way_id':req.body.osm_way_id,'osmname':req.body.osmname,'geometry':req.body.geometry}).lean()

    .then(geotable => {

        if(!geotable) {
            return res.status(404).send({
                message: "record not found " + req.query.osmname
            });            
        }
        res.json(geotable);
    }).catch(err => {
        if(err.kind === 'osmname') {
            return res.status(404).send({
                message: "record not found " + req.query.osmname
            });                
        }
        return res.status(500).send({
            message: "something wrong with name " + req.query.osmname
        });
    });
};

// for get api 
module.exports = (app) => {

   ///onlty app.get with query params not working in browser but working in postman.

    app.get('/geodata/osmname', geodata.findOne);


}

0 个答案:

没有答案