简体   繁体   中英

Loading images from couchdb database

I load user profile pictures from a CouchDB database with a function inside a ReactJS component. On my own computer, the pictures are loaded without any problem.

As expected, when others connect to Nodejs web-app server running on my machine on port 10002 , they cannot see the pictures, because of 127.0.0.1 which is localhost:

loadImage(){
    return(
        <div>
                <img src={'http://127.0.0.1:5984/passport-test/'+this.props.store.user._id+'/pic.jpg'}
                             height ='70px'/>
        </div>
    )
}

Therefore, I changed 127.0.0.1 to 192.168.145.137 which is IP address of my machine. But this time, pictures don't get loaded on my own machine and I'm getting the following error:

Failed to load resource: net::ERR_CONNECTION_REFUSED

I wonder if I'm missing something about loading pictures from couchdb database documents.

Also there is one more issue, on a web browser, the IP address and port of the couchdb database can be seen by pressing ctrl + shift + i and going to Sources tab, as shown below. Is there a way to hide the IP address and port of couchdb database.

在此处输入图片说明

This is probably because CouchDB only listens to 127.0.0.1 by default. After setting an admin user, you can change the bind_address configuration setting to your IP address (or 0.0.0.0 ). Then it should be reachable for everyone.

Alternatively, you can add a route to your Node.js server that proxies to the CouchDB attachments.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM